
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Express.js App Path Method
The app.path() method returns the canonical path. The path is returned as a string. It is better to use the req.baseUrl method since the app.path() method can be very complicated in complex cases of mounted apps.
Syntax
app.path( )
Example 1
Create a file with the name "appPath.js" and copy the following code snippet. After creating the file, use the command "node appPath.js" to run this code.
// app.path() Demo Example // Importing the express module var express = require('express'); // Initializing the express and port number var app = express(); var PORT = 3000; // Assigning express constructor var app = express() var blog = express() var blogAdmin = express() // Assigning the below url's app.use('/api', blog) blog.use('/v1', blogAdmin) // printing values as per the URLs console.dir(app.path()) console.dir(blog.path()) console.dir(blogAdmin.path())
Output
C:\home
ode>> node appPath.js '' '/api' '/api/v1'
Example 2
Let’s take a look at one more example
// express.raw() Demo Example // Importing the express module var express = require('express'); // Initializing the express and port number var app = express(); var PORT = 3000; // Assigning express constructor var app = express() var blog = express() // Assigning the below url's app.use('/api', blog) app.use('/v1', blog) // printing values as per the URLs console.dir(app.path()) // '' console.dir(blog.path()) // '/blog'
Output
C:\home
ode>> node appPath.js '' '/v1'
Advertisements