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

后端 未结 4 1568
我在风中等你
我在风中等你 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:08

    path.join will take care of unneccessary delimiters, that may occur if the given pathes come from unknown sources (eg. user input, 3rd party APIs etc.).

    So path.join('a/','b') path.join('a/','/b'), path.join('a','b') and path.join('a','/b') will all give a/b.

    Without using it, you usually would make expectations about the start and end of the pathes joined, knowing they only have no or one slash.

提交回复
热议问题