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
305
votes
19 answers

Make Axios send cookies in its requests automatically

I am sending requests from the client to my Express.js server using Axios. I set a cookie on the client and I want to read that cookie from all Axios requests without adding them manually to request by hand. This is my clientside request…
Kunok
  • 8,089
  • 8
  • 48
  • 89
300
votes
18 answers

stop all instances of node.js server

This is my first time working with Node.js and I ran into this problem: I have started a Node server through the plugin of an IDE. Unfortunately, I cannot use the IDE's terminal. So I tried to run the script from the command line. This is the…
KA.
  • 4,220
  • 5
  • 26
  • 37
293
votes
13 answers

How to include route handlers in multiple files in Express?

In my NodeJS express application I have app.js that has a few common routes. Then in a wf.js file I would like to define a few more routes. How can I get app.js to recognize other route handlers defined in wf.js file? A simple require does not…
rafidude
  • 4,496
  • 7
  • 27
  • 23
284
votes
14 answers

File uploading with Express 4.0: req.files undefined

I'm attempting to get a simple file upload mechanism working with Express 4.0 but I keep getting undefined for req.files in the app.post body. Here is the relevant code: var bodyParser = require('body-parser'); var methodOverride =…
safwanc
  • 3,351
  • 2
  • 15
  • 20
281
votes
8 answers

Difference between app.use and app.get in express.js

I'm kind of new to express and node.js, and I can't figure out the difference between app.use and app.get. It seems like you can use both of them to send information. For example: app.use('/',function(req, res,next) { res.send('Hello'); …
Andre Vorobyov
  • 2,835
  • 2
  • 13
  • 6
278
votes
22 answers

Avoid "current URL string parser is deprecated" warning by setting useNewUrlParser to true

I have a database wrapper class that establishes a connection to some MongoDB instance: async connect(connectionString: string): Promise { this.client = await MongoClient.connect(connectionString) this.db =…
Lion
  • 16,606
  • 23
  • 86
  • 148
274
votes
26 answers

How to redirect 404 errors to a page in ExpressJS?

I don't know a function for doing this, does anyone know of one?
user822159
274
votes
5 answers

What is NODE_ENV and how to use it in Express?

This is my app that I'm currently running on production. var app = express(); app.set('views',settings.c.WEB_PATH + '/public/templates'); app.set('view engine','ejs'); app.configure(function(){ app.use(express.favicon()); …
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
270
votes
6 answers

What is the difference between res.end() and res.send()?

I'm a beginner in Express.js and I'm confused by these two keywords: res.end() and res.send(). Are they the same or different?
sudheeshcm
  • 3,310
  • 4
  • 14
  • 21
267
votes
12 answers

static files with express.js

I want to serve index.html and /media subdirectory as static files. The index file should be served both at /index.html and / URLs. I have web_server.use("/media", express.static(__dirname + '/media')); web_server.use("/",…
user124114
  • 8,372
  • 11
  • 41
  • 63
266
votes
10 answers

How can I set response header on express.js assets

I need to set CORS to be enabled on scripts served by express. How can I set the headers in these returned responses for public/assets?
Dr.Knowitall
  • 10,080
  • 23
  • 82
  • 133
266
votes
4 answers

Difference between res.send and res.json in Express.js

What is actual difference between res.send and res.json as both seems to perform same operation of responding to client.
Dhanu Gurung
  • 8,480
  • 10
  • 47
  • 60
264
votes
9 answers

How can I set cookie in node js using express framework?

In my application, I need to set a cookie using the express framework. I have tried the following code but it's not setting the cookie. var express = require('express'), http = require('http'); var app = express(); app.configure(function(){ …
sachin
  • 13,605
  • 14
  • 42
  • 55
260
votes
33 answers

How to get all registered routes in Express?

I have a web application built using Node.js and Express. Now I would like to list all registered routes with their appropriate methods. E.g., if I have executed app.get('/', function (...) { ... }); app.get('/foo/:id', function (...) { ...…
Golo Roden
  • 140,679
  • 96
  • 298
  • 425
257
votes
8 answers

How can I render inline JavaScript with Jade / Pug?

I'm trying to get JavaScript to render on my page using Jade (http://jade-lang.com/) My project is in NodeJS with Express, eveything is working correctly until I want to write some inline JavaScript in the head. Even taking the examples from the…
JMWhittaker
  • 3,633
  • 3
  • 23
  • 30