Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8178415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:45:40+00:00 2026-06-06T23:45:40+00:00

In the docs for the NodeJS express module , the example code has app.use(…)

  • 0

In the docs for the NodeJS express module, the example code has app.use(...).

What is the use function and where is it defined?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T23:45:41+00:00Added an answer on June 6, 2026 at 11:45 pm

    The app object is instantiated on creation of the Express server. It has a middleware stack that can be customized in app.configure()(this is now deprecated in version 4.x).

    To setup your middleware, you can invoke app.use(<specific_middleware_layer_here>) for every middleware layer that you want to add (it can be generic to all paths, or triggered only on specific path(s) your server handles), and it will add onto your Express middleware stack. Middleware layers can be added one by one in multiple invocations of use, or even all at once in series with one invocation.
    See use documentation for more details.

    To give an example for conceptual understanding of Express Middleware, here is what my app middleware stack (app.stack) looks like when logging my app object to the console as JSON:

    stack: 
       [ { route: '', handle: [Function] },
         { route: '', handle: [Function: static] },
         { route: '', handle: [Function: bodyParser] },
         { route: '', handle: [Function: cookieParser] },
         { route: '', handle: [Function: session] },
         { route: '', handle: [Function: methodOverride] },
         { route: '', handle: [Function] },
         { route: '', handle: [Function] } ]
    

    As you might be able to deduce, I called app.use(express.bodyParser()), app.use(express.cookieParser()), etc, which added these express middleware ‘layers’ to the middleware stack. Notice that the routes are blank, meaning that when I added those middleware layers I specified that they be triggered on any route. If I added a custom middleware layer that only triggered on the path /user/:id that would be reflected as a string in the route field of that middleware layer object in the stack printout above.

    Each layer is essentially adding a function that specifically handles something to your flow through the middleware.

    E.g. by adding bodyParser, you’re ensuring your server handles incoming requests through the express middleware. So, now parsing the body of incoming requests is part of the procedure that your middleware takes when handling incoming requests — all because you called app.use(bodyParser).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using node.js and the less compiler middleware: app.configure(function() { // ... app.use(express.compiler({ src:
In http://nodejs.org/docs/v0.4.7/api/http.html#http.request There is an example that fetches some web content, but how does
I'm writing a simple NodeJS app with mongo. For connecting to mongo I use:
I am deploying a NodeJS application on CloudFoundry http://docs.cloudfoundry.com/frameworks/nodejs/nodejs.html . My application is based
i use such treeview http://docs.jquery.com/Plugins/Treeview/treeview , it saves perfect opened nodes when i click
In nodeJS I am using the passport module for authentication. I would like to
Hi Everyone I am newbie to Express + NodeJS. I come from Java and
I'm doing a simple UDP send using Node's inbuilt datagram UDP socket : http://nodejs.org/docs/v0.3.1/api/dgram.html
I would like to use the CommonJS module system in a clientside javascript application.
I'm reading the docs at http://nodejs.org/docs/v0.4.0/api/http.html#http.request , but for some reason, I can't seem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.