How to determine the OS path separator in JavaScript?

前端 未结 5 1787
你的背包
你的背包 2020-12-15 02:21

How can I tell in JavaScript what path separator is used in the OS where the script is running?

5条回答
  •  有刺的猬
    2020-12-15 02:44

    Use path module in node.js returns the platform-specific file separator.
    example

    path.sep  // on *nix evaluates to a string equal to "/"
    

    Edit: As per Sebas's comment below, to use this, you need to add this at the top of your js file:

    const path = require('path')
    

提交回复
热议问题