有沒有為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']});
怎么樣?很簡單吧,還等什么呢。