Bob*_*ian 50 shell command-line node.js
我不知道这是否重要,但我在OSX上.
我知道您可以通过键入以下内容从命令行启动浏览器:
open http://www.stackoverflow.com
Run Code Online (Sandbox Code Playgroud)
但有没有办法从nodejs命令行脚本中打开浏览器?
cti*_*ide 99
Opn现在存在,使用它.:)
安装时间:
$ npm install --save open
Run Code Online (Sandbox Code Playgroud)
用于:
const open = require('open');
// Opens the image in the default image viewer
(async () => {
await open('unicorn.png', {wait: true});
console.log('The image viewer app closed');
// Opens the url in the default browser
await open('https://sindresorhus.com');
// Specify the app to open in
await open('https://sindresorhus.com', {app: 'firefox'});
// Specify app arguments
await open('https://sindresorhus.com', {app: ['google chrome', '--incognito']});
})();
Run Code Online (Sandbox Code Playgroud)