-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
42 lines (32 loc) · 1.05 KB
/
app.js
File metadata and controls
42 lines (32 loc) · 1.05 KB
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
const express = require('express');
const helmet = require('helmet');
const bodyParser = require('body-parser');
const childProc = require('child_process');
const compression = require('compression');
const app = express();
app.use(helmet());
app.use(compression());
const port = process.env.port || 8080;
app.use(bodyParser.json()); // parse incoming requests
app.use(bodyParser.urlencoded({ extended: false }));
app.set('port', (process.env.PORT || 8080));
app.use(express.static(__dirname + '/public'));
app.set('view engine', 'pug'); // engine - pug
app.set('views', __dirname + '/views');
const routes = require('./routes/index'); // include routes
app.use('/', routes);
// catch 404 then forward to error handler
app.use((req, res, next) =>
{
let err = new Error('404, File Not Found');
err.status = 404;
next(err);
});
app.listen(app.get('port'), () =>
{
console.log(`app is running on http://localhost:${port}`);
});
childProc.exec(`open -a "Google Chrome" http://localhost:${port}`, () =>
{
console.log(`Open on: http://localhost:${port}`);
});