NodeJS Path Module Methods and Properties

Last Updated On Monday 25th Apr 2022

Path Module

	var path = require("path")
	
  • This module contains utilities to help us handle and transform file paths.
  • The following syntax is used for importing it:

Path Module Methods:

Methods Description
path.normalize(p) Used to normalize string paths, take care of the . and .. bits
path.isAbsolute(path) Determines if a path is absolute.Absolute paths always resolve to the same location
path.dirname(p) Returns a path’s directory name
path.parse(pathString) Returns an object from the path string
path.basename(p[, ext]) Returns a path’s last portion
path.format(pathObject) Returns a path string from an object

Properties for the Path Module:

Properties Description
path.delimiter Path delimiter specific to the platform and : or ;
path.win32 This also gives us access to the path methods mentioned above but only allows interaction in a way compatible with win32
path.sep File separator specific to the platform and is /
path.posix Gives access to the path methods mentioned above but only allows interaction in a way compatible with posix