Full Stack LAMP - MEAN Developer, Python developer. Certified Azure Developer. Freelance programmer/consultant/trainer.

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: /

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.