-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.js
executable file
·44 lines (37 loc) · 974 Bytes
/
start.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
44
const browserSync = require("browser-sync");
const app = require("./app");
///var http = require("http");
const port = normalizePort(process.env.PORT || "3000");
app.set("port", port);
const isProduction = "production" === process.env.NODE_ENV;
const server = app.listen(port, listening);
function listening(err) {
console.log(`Express is running on port ${server.address().port}`);
if (!isProduction) {
if (err) console.log(err);
// https://ponyfoo.com/articles/a-browsersync-primer#inside-a-node-application
browserSync({
files: ["**/*.{html,js,css,pug}"],
online: false,
open: false,
port: port + 1,
proxy: "localhost:" + port,
ui: false,
});
}
}
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}