Questions tagged [express]

Express.js is a minimal and flexible Node.js web application framework providing a robust set of features for building web applications.

Express.js is a minimal and flexible Node.js web application framework providing a robust set of features for building web applications.

The official website of Express.js is expressjs.com. The source can be found on GitHub.

Useful links:

Older versions

94248 questions
504
votes
10 answers

What is Express.js?

I am a learner in Node.js. What's Express.js? What's the purpose of it with Node.js? Why do we actually need Express.js? How is it useful for us to use with Node.js? What's Redis? Does it come with Express.js?
vinod
  • 8,350
  • 9
  • 32
  • 36
486
votes
11 answers

What does body-parser do with express?

I don't understand why we need body-parser in an Express application, as we can get data without using body-parser. And what does it do actually and how?
jiten
  • 5,005
  • 3
  • 12
  • 8
481
votes
7 answers

Understanding passport serialize deserialize

How would you explain the workflow of Passport's serialize and deserialize methods to a layman. Where does user.id go after passport.serializeUser has been called? We are calling passport.deserializeUser right after it where does it fit in the…
Anubhav
  • 7,138
  • 5
  • 21
  • 33
471
votes
26 answers

How can I set NODE_ENV=production on Windows?

In Ubuntu it's quite simple; I can run the application using: $ NODE_ENV=production node myapp/app.js However, this doesn't work on Windows. Is there a configuration file where I can set the attribute?
Jack
  • 15,614
  • 19
  • 67
  • 92
451
votes
32 answers

NodeJS / Express: what is "app.use"?

In the docs for the NodeJS express module, the example code has app.use(...). What is the use function and where is it defined?
Alexander Bird
  • 38,679
  • 42
  • 124
  • 159
448
votes
7 answers

Download a file from NodeJS Server using Express

How can I download a file that is in my server to my machine accessing a page in a nodeJS server? I'm using the ExpressJS and I've been trying this: app.get('/download', function(req, res){ var file = fs.readFileSync(__dirname +…
429
votes
4 answers

How to get a URL parameter in Express?

I am facing an issue on getting the value of tagid from my URL: localhost:8888/p?tagid=1234. Help me out to correct my controller code. I am not able to get the tagid value. My code is as follows: app.js: var express = require('express'), http =…
user2834795
  • 4,333
  • 2
  • 15
  • 10
428
votes
36 answers

Start script missing error when running npm start

I'm receiving this error when trying to debug my node application using the npm start command. Error: npm ERR! Windows_NT 6.3.9600 npm ERR! argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js"…
Andrew Moll
  • 4,903
  • 2
  • 13
  • 15
423
votes
19 answers

How do I debug error ECONNRESET in Node.js?

I'm running an Express.js application using Socket.io for a chat webapp and I get the following error randomly around 5 times during 24h. The node process is wrapped in forever and it restarts itself immediately. The problem is that restarting…
Samson
  • 2,801
  • 7
  • 37
  • 55
419
votes
31 answers

req.body empty on posts

All of a sudden this has been happening to all my projects. Whenever I make a post in nodejs using express and body-parser req.body is an empty object. var express = require('express') var bodyParser = require('body-parser') var app =…
Joseph Dailey
  • 4,735
  • 2
  • 15
  • 18
416
votes
27 answers

Request header field Access-Control-Allow-Headers is not allowed by itself in preflight response

I have come across CORS issues multiple times and can usually fix it but I want to really understand by seeing this from a MEAN stack paradigm. Before I simply added middleware in my express server to catch these things, but it looks like there is…
mibbit
  • 4,997
  • 3
  • 26
  • 34
410
votes
8 answers

How do I consume the JSON POST data in an Express application

I'm sending the following JSON string to my server. ( { id = 1; name = foo; }, { id = 2; name = bar; } ) On the server I have this. app.post('/', function(request, response) { …
neuromancer
  • 53,769
  • 78
  • 166
  • 223
405
votes
16 answers

Express.js: how to get remote client address

I don't completely understand how I should get a remote user IP address. Let's say I have a simple request route such as: app.get(/, function (req, res){ var forwardedIpsStr = req.header('x-forwarded-for'); var IP = ''; if…
Erik
  • 14,060
  • 49
  • 132
  • 218
400
votes
10 answers

Call a "local" function within module.exports from another function in module.exports?

How do you call a function from within another function in a module.exports declaration? app.js var bla = require('./bla.js'); console.log(bla.bar()); bla.js module.exports = { foo: function (req, res, next) { return ('foo'); }, …
k00k
  • 17,314
  • 13
  • 59
  • 86
390
votes
10 answers

Differences between express.Router and app.get?

I'm starting with NodeJS and Express 4, and I'm a bit confused. I been reading the Express website, but can't see when to use a route handler or when to use express.Router. As I could see, if I want to show a page or something when the user hits…
nelson687
  • 4,353
  • 3
  • 17
  • 20