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
Filter by
Sorted by
Tagged with
1214 votes
49 answers
2.0m views

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:...
DjangoRocks's user avatar
767 votes
37 answers
893k views

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 ...
mikong's user avatar
  • 8,330
1587 votes
26 answers
1.9m views

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 ...
XMen's user avatar
  • 29.9k
2105 votes
18 answers
2.1m views

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's user avatar
  • 22.8k
919 votes
24 answers
948k views

How to access POST form fields in Express

Here is my simple form: <form id="loginformA" action="userlogin" method="post"> <div> <label for="email">Email: </label> <input type="text" id="email" ...
murvinlai's user avatar
  • 49.7k
448 votes
19 answers
1.2m views

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 ...
374 votes
17 answers
551k views

No 'Access-Control-Allow-Origin' - Node / Apache Port Issue

i've created a small API using Node/Express and trying to pull data using Angularjs but as my html page is running under apache on localhost:8888 and node API is listen on port 3000, i am getting the ...
user1336103's user avatar
  • 3,859
331 votes
12 answers
492k views

Push items into mongo array via mongoose

Basically I have a mongodb collection called 'people' whose schema is as follows: people: { name: String, friends: [{firstName: String, lastName: String}] } Now, I have a ...
Neurax's user avatar
  • 3,717
452 votes
7 answers
641k views

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 ...
Thiago Miranda de Oliveira's user avatar
809 votes
31 answers
754k views

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/...
mike james's user avatar
  • 9,210
57 votes
2 answers
122k views

CORS Error: “requests are only supported for protocol schemes: http…” etc

I am trying to run a simple application. I have an Express backend which returns a JSON string when visited at localhost:4201/ticker. When I run the server and make a request to this link from my ...
Abrar Hossain's user avatar
632 votes
10 answers
667k views

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('...
Alan's user avatar
  • 46.4k
557 votes
52 answers
719k views

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("...
Masiar's user avatar
  • 20.9k
54 votes
10 answers
133k views

How to enable cors nodejs with express?

In summary I am using a viewer like api of dicom files called cornerstone, for this I connect to the WADO service of dc4chee to get the dicom, dcm4chee runs port 8080, and my application on node uses ...
M. Node's user avatar
  • 733
270 votes
12 answers
507k views

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'...
user124114's user avatar
  • 8,407
197 votes
25 answers
112k views

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 ...
spirytus's user avatar
  • 10.9k
328 votes
21 answers
674k views

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 ...
Kunok's user avatar
  • 8,449
436 votes
31 answers
510k views

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 ...
Joseph Dailey's user avatar
343 votes
14 answers
336k views

How to call a Python function from Node.js

I have an Express Node.js application, but I also have a machine learning algorithm to use in Python. Is there a way I can call Python functions from my Node.js application to make use of the power of ...
Genjuro's user avatar
  • 7,615
425 votes
8 answers
678k views

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('...
neuromancer's user avatar
  • 54.7k
342 votes
32 answers
248k views

Extend Express Request object using Typescript

I’m trying to add a property to express request object from a middleware using typescript. However I can’t figure out how to add extra properties to the object. I’d prefer to not use bracket notation ...
Isak Ågren's user avatar
  • 3,637
289 votes
14 answers
335k views

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('...
safwanc's user avatar
  • 3,401
217 votes
7 answers
279k views

Node.js global variables

I asked here: Does Node.js require inheritance? And I was told that I can set variables to the global scope by leaving out the variable. This does not work for me. That is, the following does not make ...
Harry's user avatar
  • 54k
356 votes
10 answers
609k views

How do I redirect in expressjs while passing some context?

I am using express to make a web app in node.js. This is a simplification of what I have: var express = require('express'); var jade = require('jade'); var http = require("http"); var app = express()...
Enrique Moreno Tent's user avatar
439 votes
27 answers
1.1m views

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 ...
mibbit's user avatar
  • 5,257
416 votes
16 answers
504k views

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-...
Erik's user avatar
  • 14.4k
125 votes
12 answers
317k views

Node/Express file upload

I'm using node v0.10.26 and express v4.2.0 and I'm pretty new to node. I've been beating my head against my desk for the past three or so hours trying to get a file upload form working with node. At ...
okawei's user avatar
  • 1,497
100 votes
7 answers
57k views

How to share sessions with Socket.IO 1.x and Express 4.x?

How can I share a session with Socket.io 1.0 and Express 4.x? I use a Redis Store, but I believe it should not matter. I know I have to use a middleware to look at cookies and fetch session, but don't ...
Mustafa's user avatar
  • 10.2k
689 votes
13 answers
477k views

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 ...
Melbourne2991's user avatar
605 votes
11 answers
1.1m views

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: ...
MightyMouse's user avatar
  • 13.4k
500 votes
11 answers
456k views

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's user avatar
  • 5,145
1 vote
1 answer
1k views

Can I use a file based database on Heroku?

I have a small Node.js / Express app deployed to Heroku. I'd like to use a lightweight database like NeDB to persist some data. Is it possible to periodically backup / copy a file from Heroku if I ...
jrasm91's user avatar
  • 398
478 votes
26 answers
616k views

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 ...
Jack's user avatar
  • 15.8k
339 votes
17 answers
730k views

How to access the request body when POSTing using Node.js and Express?

I have the following Node.js code: var express = require('express'); var app = express.createServer(express.logger()); app.use(express.bodyParser()); app.post('/', function(request, response) { ...
TheBlueSky's user avatar
  • 5,738
435 votes
34 answers
1.5m views

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" "...
Andrew Moll's user avatar
  • 4,973
321 votes
33 answers
547k views

Render basic HTML view?

I have a basic Node.js app that I am trying to get off the ground using the Express framework. I have a views folder where I have an index.html file. But I receive the following error when loading the ...
aherrick's user avatar
  • 20k
229 votes
23 answers
249k views

Automatic HTTPS connection/redirect with node.js/express

I've been trying to get HTTPS set up with a node.js project I'm working on. I've essentially followed the node.js documentation for this example: // curl -k https://localhost:8000/ var https = ...
Jake's user avatar
  • 5,399
41 votes
2 answers
29k views

Order of router precedence in express.js

I would like to understand the order precedence in express.js. For example, as bellow code var routes = require('./routes/index'); var users = require('./routes/users'); var api = require('./routes/...
hoanganh17b's user avatar
440 votes
4 answers
673k views

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: ...
user2834795's user avatar
  • 4,443
300 votes
13 answers
335k views

How to include route handlers in multiple files in Express? [duplicate]

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 ...
rafidude's user avatar
  • 4,566
169 votes
13 answers
393k views

res.sendFile absolute path

If I do a res.sendfile('public/index1.html'); then I get a server console warning express deprecated res.sendfile: Use res.sendFile instead but it works fine on the client side. But when I ...
Kaya Toast's user avatar
  • 5,373
277 votes
9 answers
570k views

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 ...
sachin's user avatar
  • 14.1k
485 votes
7 answers
198k views

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....
Anubhav's user avatar
  • 7,188
284 votes
9 answers
178k views

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('/',...
Andre Vorobyov's user avatar
279 votes
27 answers
387k views

How to redirect 404 errors to a page in ExpressJS?

I don't know a function for doing this, does anyone know of one?
user avatar
130 votes
16 answers
294k views

ERR_HTTP_HEADERS_SENT: Cannot set headers after they are sent to the client

I'm facing this weird issue in NodeJS when using with Passport.js, Express and Mongoose. Basically, I get an error saying "Cannot set headers after they are sent to the client" even though I don't ...
lourdesr's user avatar
  • 1,411
281 votes
22 answers
345k views

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<void> { this.client = await MongoClient.connect(...
Lion's user avatar
  • 17.3k
693 votes
10 answers
755k views

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 /...
Hanfei Sun's user avatar
  • 46.2k
690 votes
21 answers
796k views

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 ...
Chris Abrams's user avatar
  • 41.1k
230 votes
14 answers
618k views

HTTP GET Request in Node.js Express

How can I make an HTTP request from within Node.js or Express.js? I need to connect to another service. I am hoping the call is asynchronous and that the callback contains the remote server's response....
Travis Parks's user avatar
  • 8,565

1
2 3 4 5
123