Saturday 2 March 2019

Express: app.path(): Get canonical path of the application


app.path()
This method returns the canonical path of the application.

index.js
var express = require('express')

var app = express()
var appBlog = express()
var appBloguser = express()
var apBlogAdmin = express()

app.use('/blog', appBlog)
appBlog.use('/user', appBloguser)
appBlog.use('/admin', apBlogAdmin)

console.log('app path ' + app.path())
console.log('appBlog path ' + appBlog.path())
console.log('appBloguser path ' + appBloguser.path())
console.log('apBlogAdmin path ' + apBlogAdmin.path())


var listener = app.listen(3000, () => {console.log('Application started on port ' + listener.address().port);});


Run index.js, you can see below messages in console.

app path
appBlog path /blog
appBloguser path /blog/user
apBlogAdmin path /blog/admin
Application started on port 3000



Previous                                                 Next                                                 Home

No comments:

Post a Comment