Do you need to use path.join in node.js?

后端 未结 4 1586
我在风中等你
我在风中等你 2020-11-27 13:53

as everyone knows Windows does paths with backslashes where Unix does paths with forward slashes. node.js provides path.join() to always use the correct slash. So for exampl

4条回答
  •  孤独总比滥情好
    2020-11-27 14:19

    Windows filesystems have no problem using either forward or backward slashes as path separators (this has been the case since back in the DOS days). The only real issue is that Windows command-line processors (or, more specifically, Windows-native command-line utilities) tend to interpret forward slashes as option specifiers rather than path components. Therefore, you need a backslashed path if you need to pass a path to a Windows command run as a subprocess. Also, Windows API calls (and methods from higher-level languages that call the Windows API) that return paths will use backslashes, so even if you aren't passing them to subprocesses, you'll need to normalize them.

提交回复
热议问题