Languages
[Edit]
EN

TypeScript / Node.js - get platform-specific path segment separator

0 points
Created by:
Lillie-Rose-Finnegan
489

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. Install node types with the following command:

2. Import path module using:

3. 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)

4. 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. Path | Node.js v16.9.0 Documentation

See also

Edit
  1. JavaScript / Node.js - get platform-specific path segment separator

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