Express req.path Property

Beginner
⏱️ 8 min read
📚 Updated: May 2026
🎯 4 Code Examples

What you’ll learn

  • What value req.path contains in Express requests.
  • How it differs from req.url and req.originalUrl.
  • How to use path-only checks in middleware.
  • How query strings are handled separately via req.query.

Usage syntax

javascript
req.path
req.query
1

Read clean pathname from request

javascript
app.get('/search', function (req, res) {
  res.json({
    path: req.path,
    query: req.query
  });
});
2

Filter middleware by path prefix

javascript
app.use(function (req, res, next) {
  if (req.path.indexOf('/api/') === 0) {
    console.log('API request:', req.path);
  }
  next();
});

❓ FAQ

It is the pathname portion of the request URL, without query parameters.
req.path is path-only, while req.originalUrl contains path plus query string as originally received.
No. Query values are available through req.query, not req.path.
req.url may include query and can be rewritten in middleware chains; req.path is normalized pathname.
Use it for path-based checks, analytics grouping, middleware filters, and logging clean route paths.
Did you know?

req.path returns only the URL pathname (without query string), which is useful for clean route checks and logging.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

4 people found this page helpful