-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
29 lines (24 loc) · 769 Bytes
/
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
process.env.TZ = 'Europe/Madrid'
const express = require('express');
const app = express();
const routes = require('./routes');
const run_job = require('./run_job');
var chokidar = require('chokidar')
var watcher = chokidar.watch('/home/pi/project')
app.use('/', routes);
app.use((err, req, res, next) => {
res.sendStatus(err.status || 500);
});
const server = app.listen(3000, () => console.info('listening on port 3000!'));
function reloadDependencies(path) {
if (path.indexOf('.js') > -1 && path.indexOf('node_modules') === -1) {
console.log('Updating require dependencies')
server.close()
run_job.stop()
process.exit(0)
}
}
watcher.on('ready', () => {
watcher.on('add', reloadDependencies)
watcher.on('change', reloadDependencies)
})