It depends on what you are toggling honestly. You could do this with environment variables, but those are only set once you deploy your app somewhere, or require a restart of the service to read them in again. Or you could set that elsewhere like a database. It really depends on what the condition of toggling on/off is as to what would determine that.
For me if it were something that I had to restart it really means it's a variable changed infrequently. From what you're saying I would stick it in the db for application config variables or something. -warner On Wed, Jan 31, 2018 at 11:57 AM, Anton.S. <[email protected]> wrote: > Hello, first time posting here. > > I'm a javascript and node.js newbie and would like to ask for advice. > > I'm making a node server which will accept requests from a chrome > extension and a certain HTTP client. > I want the server to accept requests from the extension but only under a > certain condition. > What I had in mind was to use the HTTP client to send a POST request to > start or stop receiving requests from the extension. > Here is what I came up with: > > const express = require('express'); > const app = express(); > > process.env.MYTOGGLE = false; > > app.post('/start', function (req, res){ > // HTTP client lets the server accept requests > process.env.MYTOGGLE = true; > res.send('Accepting requests from extension...'); > }); > > app.post('/request', function (req, res){ > // extension requests go here > if(!process.env.MYTOGGLE){ > res.send('404 Not Found'); > } else { > res.send('Thanks for the data!'); > } > }); > > app.post('/stop', function (req, res){ > // HTTP client changes the condition and requests to /request give '404 > Not Found' > process.env.MYTOGGLE = false; > res.send('Not accepting requests anymore!'); > }); > > app.listen(3000); > > I've used environment variables as a demonstration to what I want to > achieve in the end. > Is there something I can use in order to store that 'toggle' variable on > the server side and give the server access to it while it's running? > > Or am I going about this the wrong way? > > Much appreciated, > Anton > > > -- > Job board: http://jobs.nodejs.org/ > New group rules: https://gist.github.com/othiym23/9886289#file- > moderation-policy-md > Old group rules: https://github.com/joyent/node/wiki/Mailing-List- > Posting-Guidelines > --- > You received this message because you are subscribed to the Google Groups > "nodejs" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/nodejs/f1ee4e2b-e853-4004-aff6-3265804a9671%40googlegroups.com > <https://groups.google.com/d/msgid/nodejs/f1ee4e2b-e853-4004-aff6-3265804a9671%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAJNTuMA1WUOD5G-LktvxWDQ4_kf3MfAZFR%3D_9jk_kmHbYrzJog%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
