const os = require('os');if (os.type() == 'windows_NT') {//windows平台}if (os.type() == 'Darwin') {//Mac}if (os.type() ==
const os = require('os');if (os.type() == 'windows_NT') {//windows平台}if (os.type() == 'Darwin') {//Mac}if (os.type() == 'linux') {//Linux平台}
window和linux已验证通过,mac待验证
通过当前系统(win,linux)配置文件路径
utils/index.js:
const os = require("os");const path = require("path");// 通过当前系统(win,linux)配置文件路径let setPathByOs = function (fileName = "") { var configPath = ""; if (os.type() == "Windows_NT") { configPath = path.resolve(process.cwd(), fileName); } if (os.type() == "Linux") { configPath = path.resolve(process.execPath, "../", fileName); } return configPath;};module.exports = { setPathByOs,};
app.js中使用:
相对根目录而言
let { setPathByOs } = require("./utils/index.js");const configPath = setPathByOs("./config_node.json");
来源地址:https://blog.csdn.net/qq_40323256/article/details/129800021
--结束END--
本文标题: nodejs中判断windows、mac或linux系统
本文链接: https://lsjlt.com/news/411235.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0