All Questions

Tagged with
Filter by
Sorted by
Tagged with
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.9k
1588 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
1214 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
919 votes
12 answers
667k 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
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
809 votes
31 answers
755k 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
767 votes
37 answers
894k 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
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
797k 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
689 votes
13 answers
478k 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
650 votes
6 answers
188k 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.1k
633 votes
10 answers
668k 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
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
582 votes
21 answers
214k 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
  • 40.4k
558 votes
52 answers
720k 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
505 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
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
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
478 votes
26 answers
617k 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
459 votes
32 answers
374k 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
452 votes
7 answers
642k 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
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 ...
440 votes
4 answers
674k 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
436 votes
31 answers
511k 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
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
425 votes
8 answers
679k 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
416 votes
16 answers
505k 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
402 votes
10 answers
288k 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
401 votes
9 answers
124k 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,463
387 votes
6 answers
227k 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.3k
374 votes
17 answers
552k 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
372 votes
25 answers
552k 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,371
359 votes
26 answers
379k 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.5k
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
349 votes
24 answers
574k 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
  • 266k
343 votes
14 answers
337k 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
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
340 votes
17 answers
731k 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,748
337 votes
4 answers
336k 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,098
335 votes
18 answers
573k 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,813
331 votes
12 answers
493k 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
329 votes
21 answers
676k 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,459
323 votes
9 answers
247k 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,249
321 votes
33 answers
548k 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
312 votes
16 answers
693k 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,354
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
13 answers
336k 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
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
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
281 votes
22 answers
346k 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

1
2 3 4 5
1553