Languages
[Edit]
EN

Node.js - get platform-specific path segment separator

3 points
Created by:
Paris-Bateman
504

In this article, we would like to show you how to get a platform-specific path segment separator in Node.js.

Quick solution:

 

Detailed description

Edit

1. Import path module using:

2. Access to path.sep property that provides the platform-specific path segment separator:

  • \ on Windows (sometimes on Japanese Windows you can see in the path ¥ used as separator)
  • / on Linux/Unix (POSIX)

3. Motivation: having access to a separator you can do platform-independent operations on the paths,
e.g. filePath.split(path.sep).

Practical example

Edit

Output (on Windows):

References

Edit
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join