How do I redirect in expressjs while passing some context?

Source: https://stackoverflow.com/questions/19035373/how-do-i-redirect-in-expressjs-while-passing-some-context


There are a few ways of passing data around to different routes. The most correct answer is, of course, query strings. You'll need to ensure that the values are properly encodeURIComponent and decodeURIComponent.
app.get('/category', function(req, res) {
  var string = encodeURIComponent('something that would break');
  res.redirect('/?valid=' + string);
});
You can snag that in your other route by getting the parameters sent by using req.query.
app.get('/', function(req, res) {
  var passedVariable = req.query.valid;
  // Do something with variable
});
For more dynamic way you can use the url core module to generate the query string for you:
const url = require('url');    
app.get('/category', function(req, res) {
    res.redirect(url.format({
       pathname:"/",
       query: {
          "a": 1,
          "b": 2,
          "valid":"your string here"
        }
     }));
 });
So if you want to redirect all req query string variables you can simply do
res.redirect(url.format({
       pathname:"/",
       query:req.query,
     });
 });
And if you are using Node >= 7.x you can also use the querystring core module
const querystring = require('querystring');    
app.get('/category', function(req, res) {
      const query = querystring.stringify({
          "a": 1,
          "b": 2,
          "valid":"your string here"
      });
      res.redirect('/?' + query);
 });
Another way of doing it is by setting something up in the session. You can read how to set it up here, but to set and access variables is something like this:
app.get('/category', function(req, res) {
  req.session.valid = true;
  res.redirect('/');
});
And later on after the redirect...
app.get('/', function(req, res) {
  var passedVariable = req.session.valid;
  req.session.valid = null; // resets session variable
  // Do something
});
There is also the option of using an old feature of Express, req.flash. Doing so in newer versions of Express will require you to use another library. Essentially it allows you to set up variables that will show up and reset the next time you go to a page. It's handy for showing errors to users, but again it's been removed by default. EDIT: Found a library that adds this functionality.
Hopefully that will give you a general idea how to pass information around in an Express application.

Forever Node.JS Express 4

Source: https://stackoverflow.com/questions/24072812/forever-node-js-express-4

Try this:
forever start ./bin/www
Let's take a look to package.json:
"scripts": {
    "start": "node ./bin/www"
},
I guess when we call npm start./bin/www will be executed at some point. Then look at the content of./bin/www:
var server = app.listen(app.get('port'), function() {
  debug('Express server listening on port ' + server.address().port);
});
so we are ready to listen for connections.

Amazon EC2 Error: listen EACCES 0.0.0.0:80

Source:  https://stackoverflow.com/questions/51020596/amazon-ec2-error-listen-eacces-0-0-0-080


You cannot run a process that listens on low ports (below 1024) without root privileges.
You either try to run as sudo, as stated above, or start to use a reverse proxy (nginx for instance), start the process on another port and use the reverse proxy to forward the calls from port 80 to whatever port you started the process on.

Renewing Facebook Graph API token automatically?

  Mã truy cập dài hạn https://developers.facebook.com/docs/facebook-login/guides/access-tokens/get-long-lived/ https://community.n8n.io/t/re...