Toggle navigation
Toggle navigation
This project
Loading...
Sign in
이찬
/
opensource_term_project
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
이찬
2020-06-12 17:26:12 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
cd53774cde42c066a45eac91996f3bd495894d35
cd53774c
1 parent
45e2e4b5
DB connecting
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
11 deletions
app.js
app.js
View file @
cd53774
const
http
=
require
(
'http'
);
const
fs
=
require
(
'fs'
);
const
url
=
require
(
'url'
);
var
app
=
http
.
createServer
(
function
(
request
,
response
)
{
var
_url
=
request
.
url
;
const
express
=
require
(
'express'
);
if
(
pathname
==
'/'
)
{
response
.
writeHead
(
200
);
response
.
end
(
__dirname
,
_url
);
}
const
bodyParser
=
require
(
'body-parser'
);
const
app
=
express
();
const
port
=
process
.
env
.
PORT
||
5000
;
app
.
use
(
bodyParser
.
json
());
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
true
}));
const
data
=
fs
.
readFileSync
(
'./database.json'
);
const
conf
=
JSON
.
parse
(
data
);
const
mysql
=
require
(
'mysql'
);
const
connection
=
mysql
.
createConnection
({
host
:
conf
.
host
,
user
:
conf
.
user
,
password
:
conf
.
password
,
port
:
conf
.
port
,
database
:
conf
.
database
});
app
.
listen
(
3000
);
\ No newline at end of file
connection
.
connect
();
app
.
get
(
'/api/visiter'
,
(
req
,
res
)
=>
{
connection
.
query
(
'SELECT * FROM visiter'
,
(
err
,
rows
,
fields
)
=>
{
res
.
send
(
rows
);
}
)
});
app
.
listen
(
port
,
()
=>
console
.
log
(
`Listening on port
${
port
}
`
));
...
...
Please
register
or
login
to post a comment