Skip to main content

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
2111 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
  • 23k
1597 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
  • 30k
1221 votes
49 answers
2.1m 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
920 votes
24 answers
956k 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.9k
916 votes
12 answers
668k 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.3k
818 votes
34 answers
776k 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,300
768 votes
37 answers
904k 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,340
698 votes
10 answers
764k 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.5k
693 votes
21 answers
808k 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.5k
688 votes
13 answers
480k 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
653 votes
6 answers
189k 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
  • 11.2k
634 votes
10 answers
677k 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.5k
608 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.5k
581 votes
21 answers
215k views

How to structure an ExpressJS application? [closed]

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 is not a beautiful way ...
Sandro Munda's user avatar
  • 40.6k
563 votes
53 answers
735k 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
  • 21.1k
504 votes
10 answers
241k 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,410
503 votes
11 answers
463k 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,175
485 votes
7 answers
200k 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
478 votes
26 answers
626k 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
463 votes
33 answers
379k 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
455 votes
7 answers
649k 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
453 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 ...
443 votes
4 answers
682k 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,473
443 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,295
436 votes
31 answers
520k 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
436 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,983
434 votes
8 answers
688k 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
422 votes
16 answers
515k 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.5k
402 votes
10 answers
289k 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.5k
402 votes
9 answers
126k views

Differences between express.Router and app.get?

I'm starting with NodeJS and Express 4, and I'm a bit confused. I have 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 ...
nelson687's user avatar
  • 4,493
387 votes
6 answers
229k 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
  • 41.4k
375 votes
17 answers
559k 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,869
374 votes
25 answers
564k 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,391
359 votes
26 answers
382k 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.7k
357 votes
10 answers
615k 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
348 votes
24 answers
578k 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
  • 268k
348 votes
33 answers
258k 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,697
345 votes
17 answers
751k 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,808
345 votes
14 answers
345k 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,665
341 votes
18 answers
583k 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,873
339 votes
23 answers
701k 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,589
339 votes
4 answers
340k 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,108
331 votes
12 answers
500k 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
324 votes
10 answers
252k 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,259
321 votes
33 answers
552k 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
  • 20.1k
315 votes
16 answers
710k views

Stop all instances of Node.js server

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 problem - I am using the ...
KA.'s user avatar
  • 4,384
305 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
13 answers
339k 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
288 votes
14 answers
339k 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,391
284 votes
9 answers
180k 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
1916