有没有为nodejs编译完成后,还要打开浏览器,输入网址,而感到烦恼呢?放心,这就来拯救你。
今天介绍的这个模块叫做open模块。它的功能就是主动打开浏览器,免去你的一些烦恼。
安装
$ npm install opn --save
用法
const opn = require('opn');
// Opens the image in the default image viewer
opn('unicorn.png').then(() => {
// image viewer closed
});
// Opens the url in the default browser
opn('http://sindresorhus.com');
// Specify the app to open in
opn('http://sindresorhus.com', {app: 'firefox'});
// Specify app arguments
opn('http://sindresorhus.com', {app: ['google chrome', '--incognito']});
怎么样?很简单吧,还等什么呢。