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.

Filter by
Sorted by
Tagged with
2072 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.5k
1560 votes
26 answers
1.8m 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.4k
1181 votes
47 answers
1.9m 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
  • 13.6k
916 votes
12 answers
664k views

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 [email protected] No repository field. npm WARN package.json fresh@...
JR Galia's user avatar
  • 17.2k
912 votes
24 answers
930k 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.1k
778 votes
31 answers
698k 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
  • 8,870
761 votes
36 answers
866k 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,270
686 votes
13 answers
470k 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
682 votes
10 answers
729k 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
  • 45.4k
675 votes
21 answers
764k 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
  • 39.9k
643 votes
6 answers
183k views

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 = ...
Tamas's user avatar
  • 11k
617 votes
10 answers
643k 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
  • 45.9k
595 votes
11 answers
1.0m 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.2k
579 votes
21 answers
213k views

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 ...
Sandro Munda's user avatar
545 votes
52 answers
680k 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.5k
504 votes
10 answers
240k views

What is Express.js? [closed]

I am a learner in Node.js. What's Express.js? What's the purpose of it with Node.js? Why do we actually need Express.js? How is it useful for us to use with Node.js? What's Redis? Does it come with ...
vinod's user avatar
  • 8,350
488 votes
11 answers
441k 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,025
481 votes
7 answers
191k 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,138
472 votes
26 answers
591k 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.6k
451 votes
32 answers
360k views

NodeJS / Express: what is "app.use"?

In the docs for the NodeJS express module, the example code has app.use(...). What is the use function and where is it defined?
Alexander Bird's user avatar
448 votes
7 answers
620k 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
430 votes
4 answers
647k 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,343
430 votes
36 answers
1.4m 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,923
427 votes
19 answers
1.1m 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 ...
422 votes
31 answers
485k 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
418 votes
27 answers
996k 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,017
411 votes
8 answers
654k 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
  • 53.9k
405 votes
16 answers
479k 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.1k
400 votes
10 answers
283k views

Call a "local" function within module.exports from another function in module.exports?

How do you call a function from within another function in a module.exports declaration? app.js var bla = require('./bla.js'); console.log(bla.bar()); bla.js module.exports = { foo: function (...
k00k's user avatar
  • 17.3k
391 votes
10 answers
119k views

Differences between express.Router and app.get?

I'm starting with NodeJS and Express 4, and I'm a bit confused. I been reading the Express website, but can't see when to use a route handler or when to use express.Router. As I could see, if I want ...
nelson687's user avatar
  • 4,363
384 votes
6 answers
219k views

What is the parameter "next" used for in Express?

Suppose you have a simple block of code like this: app.get('/', function(req, res){ res.send('Hello World'); }); This function has two parameters, req and res, which represent the request and ...
Menztrual's user avatar
  • 40.9k
368 votes
16 answers
531k 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,799
359 votes
26 answers
370k views

Express-js can't GET my static files, why?

I've reduced my code to the simplest express-js app I could make: var express = require("express"), app = express.createServer(); app.use(express.static(__dirname + '/styles')); app.listen(3001); ...
Kit Sunde's user avatar
  • 36.1k
358 votes
25 answers
517k views

How to generate unique ID with node.js

function generate(count) { var founded = false, _sym = 'abcdefghijklmnopqrstuvwxyz1234567890', str = ''; while(!founded) { for(var i = 0; i < count; i++) { ...
owl's user avatar
  • 4,231
350 votes
10 answers
592k 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
346 votes
24 answers
560k views

How do I remove documents using Node.js Mongoose?

FBFriendModel.find({ id: 333 }, function (err, docs) { docs.remove(); //Remove all the documents that match! }); The above doesn't seem to work. The records are still there. Can someone fix?...
TIMEX's user avatar
  • 261k
332 votes
4 answers
321k views

How to search in array of object in mongodb

Suppose the mongodb document(table) 'users' is { _id: 1, name: { first: 'John', last: 'Backus' }, birth: new Date('Dec 03, 1924'), death: new Date('Mar 17, 2007'), ...
vcxz's user avatar
  • 4,038
330 votes
12 answers
315k 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,425
327 votes
30 answers
222k 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,487
326 votes
12 answers
474k 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,667
323 votes
16 answers
539k views

TypeError: Router.use() requires middleware function but got a Object

There have been some middleware changes on the new version of express and I have made some changes in my code around some of the other posts on this issue but I can't get anything to stick. We had it ...
Datise's user avatar
  • 3,693
321 votes
17 answers
676k 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,546
320 votes
8 answers
234k views

Passing variables to the next middleware using next() in Express.js

I want to pass some variable from the first middleware to another middleware, and I tried doing this, but there was "req.somevariable is a given as 'undefined'". //app.js .. app.get('/...
user2791897's user avatar
  • 3,219
318 votes
31 answers
536k 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
  • 19.8k
308 votes
19 answers
605k 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,129
306 votes
4 answers
85k views

Node.js / Express.js - How does app.router work?

Before I ask about app.router I think I should explain at least what I think happens when working with middleware. To use middleware, the function to use is app.use(). When the middleware is being ...
Aust's user avatar
  • 11.6k
300 votes
18 answers
652k views

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 ...
KA.'s user avatar
  • 4,220
293 votes
13 answers
324k 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,496
284 votes
14 answers
323k 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,351
281 votes
8 answers
174k 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

1
2 3 4 5
1891