Back to Expressjs

App Path

_includes/api/en/4x/app-path.md

latest514 B
Original Source
<h3 id='app.path'>app.path()</h3>

Returns the canonical path of the app, a string.

js
var app = express()
var blog = express()
var blogAdmin = express()

app.use('/blog', blog)
blog.use('/admin', blogAdmin)

console.dir(app.path()) // ''
console.dir(blog.path()) // '/blog'
console.dir(blogAdmin.path()) // '/blog/admin'

The behavior of this method can become very complicated in complex cases of mounted apps: it is usually better to use req.baseUrl to get the canonical path of the app.