Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

exec a script on each request node.js

exec a script on each request node.js


I'm sure I can Exec a script or a function each time I exec a request (app.get or with the res and req var but I cant' find how

can you please help me



I try

var express = require('express')
, http = require('http')
, path = require('path');

var app = express();

app.use(function(err, req, res, next){

in my app.js but I never have aa in my console

my app.get are in controllers:

files = fs.readdirSync(__dirname + '/controllers');
    var name = file.replace('.js', '');
    require('./controllers/' + name)(app, models);

if I remove this code app.add works but I can't use app.get

Problem courtesy of: Ajouve


You need to use general middleware:

app.use(function (req, res, next) {
  //do stuff
Solution courtesy of: Pickels


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

exec a script on each request node.js


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription