Skip to content
Related Articles
Open in App
Not now

Related Articles

Express.js | app.path() Function

Improve Article
Save Article
  • Last Updated : 16 Mar, 2023
Improve Article
Save Article

The app.path() function returns the canonical path of the app as a string. When mounting advanced apps, the behavior of this approach can become extremely complicated. In most cases, it is better to use req.baseUrl to obtain the app’s canonical path.

Installation of the express module:

  1. You can visit the link to Install the express module. You can install this package by using this command.
npm install express
  1. After installing the express module, you can check your express version in the command prompt using the command.
npm version express
  1. After that, you can just create a folder and add a file, for example, index.js. To run this file you need to run the following command.
node index.js

Filename: index.js 


const express = require('express');
const app = express();
const PORT = 3000;
const app = express()
const blog = express()
const blogAdmin = express()
app.use('/user', blog)
blog.use('/admin', blogAdmin)
console.dir(app.path()) // ''
console.dir(blog.path()) // '/blog'
console.dir(blogAdmin.path()) // '/blog/admin'

Steps to run the program:

  1. The project structure will look like this:
  2. Make sure you have installed the express module using the following command:
npm install express
  1. Run the index.js file using the below command:
node index.js



So this is how you can use the express app.path() function that returns the canonical path of the app as a string.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!