在nodejs中,我们可以使用child_process 和os完成对shell脚本的操作
不过呢,shell脚本在不同的系统也是由区别的,这里是一个简单的案例,打开我的csdn博客
代码
            
            
              javascript
              
              
            
          
          //引入进程模块和os
//exec是个函数,可以用来执行shell脚本
const { exec } = require('child_process');
const os = require('os');
//打开浏览器的网页
const openWebUrl = (url) => {
  let type = os.platform()
  switch (type) {
    case 'win32':   //windows系统
      exec(`start ${url}`)
      break
    case 'darwin':  //苹果系统
      exec(`open ${url}`)
      break
    default:  //linux系统
      exec(`xdg-open ${url}`)
  }
}
openWebUrl('https://blog.csdn.net/m0_54741495?type=blog');在nodejs中,执行该文件,就可以成功打开了