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.js is a minimal and flexible Node.js web application framework providing a robust set of features for building web applications.

The official website of Express.js is expressjs.com. The source can be found on GitHub.

Useful links:

Older versions

94248 questions
384
votes
6 answers

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 response objects respectively. On the other hand,…
Menztrual
  • 40,867
  • 12
  • 57
  • 70
367
votes
16 answers

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 No 'Access-Control-Allow-Origin'. I tried using …
user1336103
  • 3,789
  • 4
  • 16
  • 12
359
votes
26 answers

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); My directory look like…
Kit Sunde
  • 35,972
  • 25
  • 125
  • 179
356
votes
25 answers

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++) { str += _sym[parseInt(Math.random() *…
owl
  • 4,201
  • 3
  • 22
  • 28
349
votes
10 answers

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(); var server =…
Enrique Moreno Tent
  • 24,127
  • 34
  • 104
  • 189
346
votes
24 answers

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
  • 259,804
  • 351
  • 777
  • 1,080
332
votes
5 answers

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'), contribs: ['Fortran', 'ALGOL', 'Backus-Naur…
vcxz
  • 4,038
  • 4
  • 18
  • 17
329
votes
12 answers

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 machine learning libraries?
Genjuro
  • 7,405
  • 7
  • 41
  • 61
325
votes
30 answers

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 if possible. I’m looking for a solution that…
Isak Ågren
  • 3,467
  • 2
  • 14
  • 15
325
votes
12 answers

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 very basic express application that connects to…
Neurax
  • 3,657
  • 2
  • 13
  • 18
321
votes
16 answers

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 working before hand but I can't remember what the…
Datise
  • 3,683
  • 2
  • 11
  • 12
319
votes
17 answers

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) { response.write(request.body.user); …
TheBlueSky
  • 5,526
  • 7
  • 35
  • 65
318
votes
31 answers

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 web page: Error: Cannot find module…
aherrick
  • 19,799
  • 33
  • 112
  • 188
316
votes
8 answers

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('/someurl/', middleware1,…
user2791897
  • 3,179
  • 2
  • 12
  • 7
306
votes
4 answers

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 executed, it will either call the next middleware by…
Aust
  • 11,552
  • 13
  • 44
  • 74