Created
October 23, 2017 15:54
-
-
Save xeoncross/39d827295c2eaa09c5de9687c03e905f to your computer and use it in GitHub Desktop.
Simple long-running node process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const app = express(); | |
let isOn = true | |
// Testing | |
app.get('/off', (req, res) => { | |
isOn = false | |
res.json({ method: req.method, path: req.path, on: isOn }); | |
}); | |
app.get('/on', (req, res) => { | |
isOn = true | |
res.json({ method: req.method, path: req.path, on: isOn }); | |
}); | |
// Report what the current status is | |
setInterval(() { | |
console.log(isOn); | |
}, 1000); | |
// The "catchall" handler: for any request that doesn't | |
// match one above, send back React's index.html file. | |
// app.get('*', (req, res) => { | |
// res.sendFile(path.join(__dirname+'/client/build/index.html')); | |
// }); | |
app.listen(3000, (err) => { | |
if (err) throw err; | |
console.log(`> Ready on http://localhost:${port}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment