-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
43 lines (34 loc) · 1.11 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//set up the server
const express = require( "express" );
const logger = require("morgan");
const app = express();
const port = 8080;
//configure express to parse URL-encoded POST request bodies (traditional forms)
//included in express
app.use(express.urlencoded({extended: false}));
// define middleware that logs all incoming requests
app.use(logger("dev"));
// define middleware that serves static resources in the public directory
app.use(express.static(__dirname + '/public'));
// define a route for the default home page
app.get( "/", ( req, res ) => {
res.sendFile( __dirname + "/views/index.html" );
} );
// define a route for the stuff inventory page
app.get( "/home", ( req, res ) => {
res.sendFile( __dirname + "/views/home.html" );
} );
// define a route for the item detail page
app.get( "/stuff/item", ( req, res ) => {
res.sendFile( __dirname + "/views/item.html" );
} );
const insert_stuff_sql = `
INSERT INTO STUFF
(item, quantity)
VALUES
(?,?)
`
// start the server
app.listen( port, () => {
console.log(`App server listening on ${ port }. (Go to http://localhost:${ port })` );
} );