node package manager


path-extra contains methods that aren't included in the vanilla Node.js path package.

Node.js: path-extra

This module simply modifies the Node.js 'path' object with extra methods. It is a drop in replacement for the path module.

$ npm install path-extra
var path = require('path-extra');

You can still use all of the vanilla Node.js path methods.

Replaces the extension from path with extension and returns the updated path string.

From the module replace-ext.


path.replaceExt('dir/', '.html')
// => 'dir/file.html' 

A path.normalize() that trims trailing slashes. Useful for comparing file paths.


// => /foo/bar/baz/asdf/ 
// => /foo/bar/baz/asdf 

A smart wrapper for path.basename().

  • When includeExt is false, returns the basename without an extension (path.basename(filePath, path.extname(filePath))).
  • When includeExt is true, works like path.basename(filePath).
  • includeExt is false by default.


// => file 
path.base('path/to/', false)
// => file 
path.base('path/to/', true)
// => 

homedir(), tempdir(), and datadir() have been removed in version 4.0.0. Please use the ospath module instead.

(The MIT License)

Copyright (c) 2011-2015 JP Richardson