Questions tagged [node.js-connect]

Connect is a middleware framework for Node.js. It processes or decorates HTTP requests and responses to provide features such as session handling, authentication, asset management or compression.

298 questions
28
votes
7 answers

Proper way to remove middleware from the Express stack?

Is there a canonical way to remove middleware added with app.use from the stack? It seems that it should be possible to just modify the app.stack array directly, but I wonder if there is a documented method I should consider first.
Brad
  • 159,648
  • 54
  • 349
  • 530
26
votes
4 answers

How can I add CORS-Headers to a static connect server?

I am writing a little demo web server delivering static html,css and javascript. The server looks like (function () { "use strict"; var http = require("http"); var connect = require('connect'); var app = connect() …
afx
  • 853
  • 1
  • 9
  • 11
26
votes
1 answer

What is the correct way to "end" a request from express/connect middleware?

Assuming I have middleware such as this; var express = require('express'); var app = express(); app.use(function (req, res, next) { var host = "example.com"; if (req.host !== host) { res.redirect(301, host + req.originalUrl); …
Isaac
  • 1,677
  • 3
  • 15
  • 22
25
votes
4 answers

Node.js / Express.js - How to override/intercept res.render function?

I'm building a Node.js app with Connect/Express.js and I want to intercept the res.render(view, option) function to run some code before forwarding it on to the original render function. app.get('/someUrl', function(req, res) { res.render…
25
votes
3 answers

in express.js, any way to capture request to both json and html in one function?

Does anybody know a way in express.js to capture requests in a single function for both html and json? Essentially I want a single route for both /users and /users.json - like rails does with its routes -> controller. That way, I can encapsulate…
justinjmoses
  • 487
  • 1
  • 5
  • 11
21
votes
2 answers

Difference between Express and Connect npm packages

I have been using express webservers since I started working on Node.js and a few days ago I came across this new (to me) web server, called connect. Can anyone point out, what are the differences between the express and connect? When should we use…
Harshal Yeole
  • 4,812
  • 1
  • 21
  • 43
21
votes
5 answers

Change cookie expiration in Express

Because I didn't define a maxAge when calling expressServer.use(express.session({params})) the cookie's expiration is set as "Session". I would like to add a "remember me" feature when logging in. If "remember me" is selected, the expiration will…
user1161657
  • 971
  • 2
  • 10
  • 24
20
votes
1 answer

What does the bodyParser() in connect middleware do?

I'm doing a tutorials on node.js, and the lesson is teaching me how to create a server using node. In the code below, what does the connect.bodyParser() line do? var app = connect() .use(connect.bodyParser()) .use(connect.static('public')) …
Rich
  • 5,603
  • 9
  • 39
  • 61
19
votes
1 answer

Middleware design pattern in Node.js: Connect

This question extends that of What is Node.js' Connect, Express and "middleware"? I'm going the route of learning Javascript -> Node.js -> Connect -> Express -> ... in order to learn about using a modern web development stack. I have a background in…
gone
  • 2,587
  • 6
  • 25
  • 32
19
votes
1 answer

Using static(), staticCache(), and compress() node.js connect middleware

I have an Express 3.0 app and I'm trying to use the static(), staticCache(), and compress() middleware to serve and compress my static files. This is my current app.configure() function: app.configure(function() { …
Bill
  • 25,119
  • 8
  • 94
  • 125
18
votes
3 answers

MongoDB: Error setting TTL index on collection : sessions

Initially this error message started appearing very infrequently, but started to appear more regularly and now appears 4/5 times I run my application. I'm handling my session store with Mongo and as I understand it, the TTL index is used to make the…
Dan Prince
  • 29,491
  • 13
  • 89
  • 120
16
votes
4 answers

How to totally prevent HTTP 304 responses in Connect/Express static middleware?

At times during development, it would be really nice to prevent HTTP 304 responses (in favor of 200's), and cause the Connect/Express static middleware to read every response from the filesystem, rather than do any caching at all. I have tried…
Jacob Marble
  • 28,555
  • 22
  • 67
  • 78
15
votes
3 answers

Node.js - cannot find module

I'm using Node Boilerplate and it all worked fine until I decided create another project on top of it (in another dir). Now I have exactly the same code base (this project AS IS) in two different folders. I can run one of it without any problems but…
user80805
  • 6,088
  • 5
  • 28
  • 31
15
votes
3 answers

How to have a NodeJS/connect middleware execute after responde.end() has been invoked?

I would like to achieve something like this: var c = require('connect'); var app = c(); app.use("/api", function(req, res, next){ console.log("request filter 1"); next(); }); app.use("/api", function(req, res, next){ …
Peter Aron Zentai
  • 11,482
  • 5
  • 41
  • 71
13
votes
3 answers

How does this work? Optional first argument used in Express (err, req, res, next) or (req, res, next)

With Express / Connect I can set up an middleware function in either of the formats: function(req, res, next) // first argument will be a request Or function(err, req, res, next) // first argument will be an error Stepping back from Express,…
Ross
  • 14,266
  • 12
  • 60
  • 91
1
2
3
19 20