Skip to content

Instantly share code, notes, and snippets.

@adnanmc
Created January 27, 2018 03:47
Show Gist options
  • Save adnanmc/787430772570b9da844df7c401243ec1 to your computer and use it in GitHub Desktop.
Save adnanmc/787430772570b9da844df7c401243ec1 to your computer and use it in GitHub Desktop.
const express = require('express');
const bodyParser = require('body-parser');
process.env.dataFeed = 'off';
process.env.intervalObject = null;
var app = express();
const port = 3000;
app.use(bodyParser.json());
app.get('/on', (req, res) => {
let dataFeedStatus = process.env.dataFeed;
if (dataFeedStatus === 'off') {
process.env.dataFeed = 'on';
res.send('process started');
process.env.intervalObject = setInterval(() =>{
console.log('running');
}, 5000);
} else if (dataFeedStatus === 'on') {
res.send('already running');
}
});
app.get('/off', (req, res) => {
let dataFeedStatus = process.env.dataFeed;
if (dataFeedStatus === 'on') {
process.env.dataFeed = 'off';
if (process.env.intervalObject != null) {
clearInterval(process.env.intervalObject);
process.env.intervalObject = null;
}
res.send('process stopped');
} else if(dataFeedStatus === 'off') {
res.send('process is already off')
}
});
app.listen(port, () => {
console.log(`Started up at port ${port}`);
});
module.exports = {app};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment