94,957 questions
2127
votes
19
answers
2.2m
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?
1239
votes
49
answers
2.2m
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:...
917
votes
12
answers
670k
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@...
773
votes
39
answers
935k
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 ...
706
votes
10
answers
789k
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 /...
655
votes
6
answers
194k
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 = ...
617
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: ...
578
votes
53
answers
772k
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("...
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 ...
485
votes
27
answers
649k
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 ...
465
votes
19
answers
1.4m
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 ...
455
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 ...
443
votes
34
answers
1.6m
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" "...
438
votes
32
answers
538k
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 ...
405
votes
9
answers
131k
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 ...
388
votes
25
answers
602k
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++) {
...
378
votes
17
answers
576k
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 ...
362
votes
27
answers
388k
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);
...
360
votes
10
answers
631k
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();...
354
votes
25
answers
777k
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 ...
350
votes
24
answers
586k
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?
333
votes
12
answers
513k
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 ...
332
votes
16
answers
783k
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 ...
307
votes
13
answers
348k
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 ...
293
votes
6
answers
464k
views
What is NODE_ENV and how to use it in Express?
This is my app that I'm currently running on production.
var app = express();
app.set('views',settings.c.WEB_PATH + '/public/templates');
app.set('view engine','ejs');
app.configure(function(){
...