Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodejs express app.use method

I'm working on the following legacy code:

var express = require('express');
var app = express.createServer();

app
.use('/run!', getUrl('app.sys', '/run'))
.use('/stat', getUrl('app.sys'))

I'm having troubles finding documentation for the "use" method. I found some usage examples but in all of them it appeared to be getting one argument and here it gets 2. Could you please help me figure out what is the meaning of the use statement here?

Thanks, Li

like image 554
user429400 Avatar asked Aug 09 '12 09:08

user429400


1 Answers

app.use means that you will execute a middleware in the order that you give it on the program.

In your example getUrl is the middleware and the string you have as first parameter is a path. So only with that path or 'url' the middleware will be executed.

Not sure tough what getUrl function does there.

If you want to read more about "use" try the official documentation.

http://expressjs.com/api.html#app.use

like image 77
fernandopasik Avatar answered Sep 28 '22 05:09

fernandopasik