• 0

path.join in nodejs

path.join() does two things :

  • Joins all given path segments together using the platform specific separator as a delimiter
  • Normalizes the resulting path
path.join('src/', 'js/Router.jsx');

'src/js/Router.jsx' on OSX and Linux

'srcjsRouter.jsx' on Windows
Here, it normalizes the path by removing extra /.
Recommended way to use path.join to make it work across platform.
path.join(__dirname, 'src', 'js', 'Router.jsx');
Note that we are just specifying the folder (or directory) name. And let path.join add OS specific separators.