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
188
votes
20 answers

Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED

I working with node.js by expressjs I try to store an account to session. So, i try to test to use session with code in expressjs var RedisStore =…
Huy Tran
  • 4,371
  • 10
  • 34
  • 38
187
votes
6 answers

When to use next() and return next() in Node.js

Scenario: Consider the following is the part of code from a node web app. app.get('/users/:id?', function(req, res, next){ var id = req.params.id; if (id) { // do something } else { next(); //or return next(); …
Amol M Kulkarni
  • 21,143
  • 34
  • 120
  • 164
186
votes
35 answers

Failed to load c++ bson extension

A total node noob here. I've been trying to set up a sample node app but the following error keeps popping up every time I try to run: node app Failed to load c++ bson extension, using pure JS version events.js:72 throw er; // Unhandled…
Theja
  • 2,448
  • 3
  • 14
  • 18
185
votes
13 answers

Can't get rid of header X-Powered-By:Express

I am running a server on nodejs with express. I can't seem to get rid of the header: X-Powered-By:Express I was wondering if there is any way to get rid of this header or do I have to live with it?
tyronegcarter
  • 3,876
  • 4
  • 21
  • 24
185
votes
7 answers

What does "./bin/www" do in Express 4.x?

I just started to learn about Express 4.0 in my Node.js app, and I found that it generated ./bin/www file, on which only the application server and port settings are written and everything others like middleware and routing is defined in ./app.js…
Blaszard
  • 30,954
  • 51
  • 153
  • 233
184
votes
21 answers

How to update a record using sequelize for node?

I'm creating a RESTful API with NodeJS, express, express-resource, and Sequelize that is used to manage datasets stored in a MySQL database. I'm trying to figure out how to properly update a record using Sequelize. I create a model: module.exports =…
a_arias
  • 3,036
  • 2
  • 21
  • 20
181
votes
3 answers

Error handling principles for Node.js + Express.js applications?

It seems like error reporting/handling is done differently in Node.js+Express.js applications compared to other frameworks. Am I correct in understanding that it works as follows? A) Detect errors by receiving them as parameters to your callback…
clint
  • 14,402
  • 12
  • 70
  • 79
180
votes
24 answers

node.js, Error: Cannot find module 'express'

I am new to Node.js, try to learn express to build my first web application. I got stuck on my very first sample code and need some help to get it running. Before I post this question, I did search on stack overflow, found some similar questions…
qinking126
  • 11,385
  • 25
  • 74
  • 124
176
votes
9 answers

Express next function, what is it really for?

Have been trying to find a good description of what the next() method does. In the Express documentation it says that next('route') can be used to jump to that route and skip all routes in between, but sometimes next is called without arguments.…
Andreas Selenwall
  • 5,705
  • 11
  • 45
  • 58
176
votes
3 answers

how to remove X-Powered-By in ExpressJS

I want to remove X-Powered-By for Security,Save Bandwidth in ExpressJS(node.js). how to do it? it could be filter(app.use) ? app.use(function(req,res,next_cb){ /* remove X-Powered-By header */ next_cb(); }
MajidTaheri
  • 3,813
  • 6
  • 28
  • 46
174
votes
19 answers

NodeJS: How to get the server's port?

You often see example hello world code for Node that creates an Http Server, starts listening on a port, then followed by something along the lines of: console.log('Server is listening on port 8000'); But ideally you'd want this…
David Tang
  • 92,262
  • 30
  • 167
  • 149
173
votes
7 answers

What are express.json() and express.urlencoded()?

I cannot find any documentation on express.json() and express.urlencoded(). What do each of them do exactly?
user3450695
  • 2,281
  • 4
  • 16
  • 16
172
votes
9 answers

How to access a preexisting collection with Mongoose?

I have a large collection of 300 question objects in a database test. I can interact with this collection easily through MongoDB's interactive shell; however, when I try to get the collection through Mongoose in an express.js application I get an…
theabraham
  • 15,840
  • 9
  • 42
  • 41
171
votes
15 answers

Node.js Error: Cannot find module express

I wrote my first node.js app, but it can't find express library: C:\ChatServer\Server>node server.js module.js:340 throw err; ^ Error: Cannot find module 'express' at Function.Module._resolveFilename (module.js:338:15) at…
Dmitry
  • 7,457
  • 12
  • 57
  • 83
169
votes
9 answers

How can I get Express to output nicely formatted HTML?

When using Express for Node.js, I noticed that it outputs the HTML code without any newline characters or tabs. Though it may be more efficient to download, it's not very readable during development. How can I get Express to output nicely formatted…
Stephen
  • 7,994
  • 9
  • 44
  • 73