In express app.js I define uploadDir = "./tmp", but how can I access it later?
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser({uploadDir:'./tmp', keepExtensions: true})); // <--
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
Arguments to middleware like
bodyParser
go straight through to the middleware. All of the Express middleware is provided by Connect, so it doesn't even know anything about Express. TheuploadDir
is captured in themultipart
closure of the multipart middleware. It is stored via the closure, and never stored anywhere else, or passed to Express, so the only way to access the original value is to access it as part of theoptions
object initially passed in. There is no other way.If you want that value to be accessible by reading from
app
(as you said in your comment), then you should set it on there yourself separately. That said, this method is a bit ugly and means that you have to set the value twice.