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
2069
votes
18 answers

Writing to files in Node.js

I've been trying to find a way to write to a file when using Node.js, but with no success. How can I do that?
Gjorgji
  • 22,458
  • 10
  • 31
  • 39
1560
votes
26 answers

How to get GET (query string) variables in Express.js on Node.js?

Can we get the variables in the query string in Node.js just like we get them in $_GET in PHP? I know that in Node.js we can get the URL in the request. Is there a method to get the query string parameters?
XMen
  • 29,384
  • 41
  • 99
  • 151
1176
votes
47 answers

Error: Can't set headers after they are sent to the client

I'm fairly new to Node.js and I am having some issues. I am using Node.js 4.10 and Express 2.4.3. When I try to access http://127.0.0.1:8888/auth/facebook, i'll be redirected to http://127.0.0.1:8888/auth/facebook_callback. I then received the…
DjangoRocks
  • 13,598
  • 7
  • 37
  • 52
916
votes
12 answers

Error "npm WARN package.json: No repository field"

I installed Express.js with the following command: sudo npm install -g express I get the following warnings: npm WARN package.json range-parser@0.0.4 No repository field. npm WARN package.json fresh@0.1.0 No repository field. npm WARN package.json…
JR Galia
  • 17,229
  • 19
  • 92
  • 144
909
votes
24 answers

How to access POST form fields in Express

Here is my simple form:
murvinlai
  • 48,919
  • 52
  • 129
  • 177
776
votes
31 answers

Error: request entity too large

I'm receiving the following error with express: Error: request entity too large at module.exports (/Users/michaeljames/Documents/Projects/Proj/mean/node_modules/express/node_modules/connect/node_modules/raw-body/index.js:16:15) at json…
mike james
  • 8,840
  • 3
  • 18
  • 21
761
votes
36 answers

Why doesn't adding CORS headers to an OPTIONS route allow browsers to access my API?

I am trying to support CORS in my Node.js application that uses the Express.js web framework. I have read a Google group discussion about how to handle this, and read a few articles about how CORS works. First, I did this (code is written in…
mikong
  • 8,270
  • 3
  • 16
  • 15
686
votes
13 answers

bodyParser is deprecated express 4

I am using express 4.0 and I'm aware that body parser has been taken out of the express core, I am using the recommended replacement, however I am getting body-parser deprecated bodyParser: use individual json/urlencoded middlewares…
Melbourne2991
  • 11,707
  • 12
  • 44
  • 82
680
votes
10 answers

How to access the GET parameters after "?" in Express?

I know how to get the params for queries like this: app.get('/sample/:id', routes.sample); In this case, I can use req.params.id to get the parameter (e.g. 2 in /sample/2). However, for url like /sample/2?color=red, how can I access the variable…
Hanfei Sun
  • 45,281
  • 39
  • 129
  • 237
675
votes
21 answers

How to get the full URL in Express?

Let's say my sample URL is http://example.com/one/two and I say I have the following route app.get('/one/two', function (req, res) { var url = req.url; } The value of url will be /one/two. How do I get the full URL in Express? For example, in…
Chris Abrams
  • 39,732
  • 19
  • 51
  • 57
642
votes
6 answers

Express.js - app.listen vs server.listen

This may be a very basic question but I simply don't get it. What is the difference between creating an app using Express.js and starting the app listening on port 1234, for example: var express = require('express'); var app =…
Tamas
  • 10,953
  • 13
  • 47
  • 77
617
votes
10 answers

Enabling HTTPS on express.js

I'm trying to get HTTPS working on express.js for node, and I can't figure it out. This is my app.js code. var express = require('express'); var fs = require('fs'); var privateKey = fs.readFileSync('sslcert/server.key'); var certificate =…
Alan
  • 45,915
  • 17
  • 113
  • 134
594
votes
11 answers

Proper way to return JSON using node or Express

So, one can attempt to fetch the following JSON object: $ curl -i -X GET http://echo.jsontest.com/key/value/anotherKey/anotherValue HTTP/1.1 200 OK Access-Control-Allow-Origin: * Content-Type: application/json; charset=ISO-8859-1 Date: Wed, 30 Oct…
MightyMouse
  • 13,208
  • 8
  • 33
  • 43
579
votes
21 answers

ExpressJS How to structure an application?

I'm using the ExpressJS web framework for NodeJS. People using ExpressJS put their environments (development, production, test...), their routes etc on the app.js. I think that it's not a beautiful way because when you have a big application, app.js…
Sandro Munda
  • 39,921
  • 24
  • 98
  • 123
542
votes
52 answers

Express.js req.body undefined

I have this as configuration of my Express server app.use(app.router); app.use(express.cookieParser()); app.use(express.session({ secret: "keyboard cat" })); app.set('view engine', 'ejs'); app.set("view options", { layout: true }); //Handles post…
Masiar
  • 20,450
  • 31
  • 97
  • 140
1
2 3
99 100