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
217
votes
11 answers

Passport.js - Error: failed to serialize user into session

I got a problem with the Passport.js module and Express.js. This is my code and I just want to use a hardcoded login for the first try. I always get the message: I searched a lot and found some posts in stackoverflow but I didnt get the…
user2244925
  • 2,314
  • 3
  • 14
  • 11
216
votes
6 answers

How to implement a secure REST API with node.js

I start planning a REST API with node.js ,express and mongodb. The API provides data for a website (public and private area) and maybe later a mobile app. The frontend will be developed with AngularJS. For some days I read a lot about securing REST…
tschiela
  • 5,231
  • 4
  • 28
  • 35
215
votes
3 answers

What are "res" and "req" parameters in Express functions?

In the following Express function: app.get('/user/:id', function(req, res){ res.send('user' + req.params.id); }); What are req and res? What do they stand for, what do they mean, and what do they do? Thanks!
expressnoob
  • 2,287
  • 3
  • 16
  • 7
208
votes
12 answers

express throws error as `body-parser deprecated undefined extended`

In my node app, I am using express. all works fine, But i am getting error in the cmd. I use all are updated modules... my code : var express = require('express'); var bodyParser = require('body-parser'); var jade = require('jade'); var app =…
3gwebtrain
  • 14,640
  • 25
  • 121
  • 247
200
votes
47 answers

Cannot overwrite model once compiled Mongoose

Not Sure what I'm doing wrong, here is my check.js var db = mongoose.createConnection('localhost', 'event-db'); db.on('error', console.error.bind(console, 'connection error:')); var a1= db.once('open',function(){ var user = mongoose.model('users',{…
Anathema.Imbued
  • 3,271
  • 4
  • 17
  • 18
200
votes
10 answers

MongoDB/Mongoose querying at a specific date?

Is it possible to query for a specific date ? I found in the mongo Cookbook that we can do it for a range Querying for a Date Range Like that : db.posts.find({"created_on": {"$gte": start, "$lt": end}}) But is it possible for a specific date ? This…
Unitech
  • 5,781
  • 5
  • 40
  • 47
198
votes
29 answers

npm can't find package.json

I'm trying to install the dependencies of some example: npm's express 2.5.8 that I've downloaded, but all of the apps throw the same error: c:\node\stylus>npm install -d npm info it worked if it ends with ok npm info using npm@1.1.1 npm info using…
imjp
  • 6,495
  • 10
  • 48
  • 58
198
votes
34 answers

ExpressJS - throw er Unhandled error event

I created expressjs application using the following commands: express -e folderName npm install ejs --save npm install When I run the application with: node app.js, I have the following errors: events.js:72 throw er; // Unhandled 'error' event …
JR Galia
  • 17,229
  • 19
  • 92
  • 144
195
votes
25 answers

How to properly reuse connection to Mongodb across NodeJs application and modules

I've been reading and reading and still am confused on what is the best way to share the same database (MongoDb) connection across whole NodeJs app. As I understand connection should be open when app starts and reused between modules. My current…
spirytus
  • 10,726
  • 14
  • 61
  • 75
195
votes
2 answers

Difference between `npm start` & `node app.js`, when starting app?

I have installed an application using the command express new 'filename'. I have just learned that you can start an application using: npm start Thus far I have used: node app.js to start my server. Anyone know what the difference is between the…
ReneGAED
  • 2,246
  • 2
  • 15
  • 11
193
votes
8 answers

Rest with Express.js nested router

Suppose I want to have REST endpoints which look roughly like this: /user/ /user/user_id /user/user_id/items/ /user/user_id/items/item_id CRUD on each if makes sense. For example, /user POST creates a new user, GET fetches all users.…
huggie
  • 17,587
  • 27
  • 82
  • 139
192
votes
17 answers

create a trusted self-signed SSL cert for localhost (for use with Express/Node)

Trying to follow various instructions on creating a self-signed cert for use with localhost, Most of the instructions seem to be for IIS, but I'm trying to use Nodejs/Express. None of them work properly because while the cert gets installed, it…
JasonS
  • 7,443
  • 5
  • 41
  • 61
192
votes
4 answers

Express res.sendfile throwing forbidden error

I have this code: res.sendfile( '../../temp/index.html' ) However, it throws this error: Error: Forbidden at SendStream.error (/Users/Oliver/Development/Personal/Reader/node_modules/express/node_modules/send/lib/send.js:145:16) at SendStream.pipe…
user1082754
190
votes
5 answers

express.json vs bodyParser.json

I'm writing a relatively new app and was wondering which I should use: express.json() or bodyParser.json() Can I assume they do the same thing. I would like to just use express.json() as it is built in already.
user7742676
190
votes
15 answers

Error: No default engine was specified and no extension was provided

I am working through setting up a http server using node.js and engine. However, I keep running into issues that I have little information on how to resolve I would appreciate some help solving this please. Error: No default engine was specified…
Kobojunkie
  • 6,375
  • 31
  • 109
  • 164