forked from Rahul-Bisht/fivenations
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
30 lines (24 loc) · 722 Bytes
/
Copy pathserver.js
File metadata and controls
30 lines (24 loc) · 722 Bytes
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
var Promise = require('es6-promise').Promise;
var express = require('express');
var app;
var server;
module.exports = {
start: function(port, dir) {
if (app) throw 'Server is already running!';
if (!port) port = 8612;
if (!dir) dir = 'build/';
app = express();
app.use(express.static(dir));
return new Promise(function(resolve) {
server = app.listen(port, function() {
console.log('Express application is listening on port ' + port);
resolve();
});
});
},
stop: function() {
if (!server) return;
return Promise.resolve()
.then(server.close.bind(server));
}
};