Skip to content

Node.js – Get Platform-Specific Path Separator

The path module provides utilities for working with file and directory paths. It can be accessed using:

const path = require('path');

You can get the platform-specific path segment separator with path.sep Property. This property returns a string that represents a platform-specific path separator. The returned value is

  • \ on Windows
  • / on POSIX

For example, on POSIX:

const path = require('path');
console.log(path.sep);
// Returns: \

On Windows:

const path = require('path');
console.log(path.sep);
// Returns: /

Comments are closed, but trackbacks and pingbacks are open.