close
The Wayback Machine - https://web.archive.org/web/20240802193117/https://www.geeksforgeeks.org/node-js-path-normalize-method/
Open In App

Node.js path.normalize() Method

Last Updated : 13 Oct, 2021
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report

The path.normalize() method is used to normalize the given path. Normalization resolves the (.) and (..) segments of the path to their correct form. If the method encounters multiple path separators, it replaces all of them by a single platform-specific path separator. This method preserves all trailing separators.

Syntax:

path.normalize( path )

Parameters: This method accepts single parameter path which holds the file path that would be normalized. A TypeError is thrown if this parameter is not a string.

Return Value: It returns a string with the normalized form of the path.

Below example illustrates the path.normalize() method in node.js:

Example:




// Node.js program to demonstrate the   
// path.normalize() method
  
// Import the path module
const path = require('path');
   
path1 = path.normalize("/users/admin/.");
console.log(path1)
   
path2 = path.normalize("/users/admin/..");
console.log(path2)
   
path3 = path.normalize("/users/admin/../comments")
console.log(path3);
   
path4 = path.normalize("/users///admin///comments")
console.log(path4);


Output:

\users\admin
\users
\users\comments
\users\admin\comments

Reference: https://nodejs.org/api/path.html#path_path_normalize_path


Previous Article
Next Article

Similar Reads

Node Jimp | normalize
The normalize() function is an inbuilt function in Nodejs | Jimp which normalizes the colors of an image by computing a histogram. Syntax: normalize(cb) Parameter: cb - This is an optional parameter that is invoked when compilation is complete. Input Images: Setup Environment : npm init -yInstall Dependencies : npm install jimp Example 1: In this e
1 min read
HTML DOM normalize() Method
The normalize() method in HTML is used to merge the adjacent text nodes with the first text node and flush out the empty nodes. The normalize() method does not require any parameter. Syntax: node.normalize() Example 1: In this example, we will use normalize() method. C/C++ Code <!DOCTYPE html> <html> <head> <title> DOM norma
2 min read
JavaScript String normalize() Method
JavaScript String normalize() method returns a Unicode normalization form of a given input string. If the given input is not a string, then at first it will be converted into a string then this method will work. Syntaxstring.normalize([form])Parameters Here the parameter is formed which is of many types- NFC: Normalization Form Canonical Compositio
3 min read
TypeScript String normalize() Method
The String.prototype.normalize() method in TypeScript is used to return a Unicode normalization form of a given string. This method ensures that the string conforms to one of the standard Unicode normalization forms. Syntaxstring.normalize(form: string): stringParameters:form: Here are the different Unicode normalization forms: NFC: Normalization F
2 min read
PHP | DOMNode normalize() Function
The DOMNode::normalize() function is an inbuilt function in PHP which is used to remove empty text nodes and merge adjacent text nodes in this node and all its children. Syntax: void DOMNode::normalize( void ) Parameters: This function doesn’t accept any parameters. Return Value: This function does not return any value. Below examples illustrate th
2 min read
jQuery Mobile Rangeslider normalize Event
jQuery Mobile is an HTML5 based user interface system designed to make responsive websites and apps that are accessible on all smartphone, tablet, and desktop devices. The rangeslider widget of jQuery Mobile is a double handle slider. The sliders have a min and a max value to be set and we can choose from the range in between min and max. In this a
2 min read
Normalize in Bootstrap
In Bootstrap, Normalize is a CSS file that aims to provide a consistent set of styles across all modern browsers, making it easier to create consistent and predictable designs. It is a reset stylesheet that overrides default styles provided by browsers and sets them to a consistent baseline. In this article, we will know about Normalize in Bootstra
4 min read
How to Normalize State in Redux Applications ?
In Redux applications, efficient state management is essential for scalability and maintainability. Normalization is a technique used to restructure complex state data into a more organized format, improving performance and simplifying state manipulation. This article covers the concept of normalization in Redux, exploring various approaches, steps
3 min read
Difference between reset vs normalize CSS
Ensuring a consistent user experience across different browsers can be a challenging task for web developers. Each browser has its built-in styles, which can vary depending on the operating system or the browser itself. This variation can lead to inconsistencies in how a webpage is displayed to users. To address this issue, developers use two main
4 min read
Normalize.css
Normalize.css is a lightweight CSS file designed to make browsers render HTML elements consistently and adhere to modern standards. Developed by Nicolas Gallagher, co-creator of Twitter Bootstrap, it serves as a contemporary alternative to traditional CSS resets. Unlike resets, Normalize.css preserves useful default styles, establishes base styles
5 min read
three90RightbarBannerImg