首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Npm "scripts":"start“运行express并打开url

Npm "scripts":"start“运行express并打开url
EN

Stack Overflow用户
提问于 2016-02-08 10:15:13
回答 3查看 26.7K关注 0票数 36

我在package.json中有这个起始参数

代码语言:javascript
复制
"scripts": {
    "start": "node bin/www"
  },

当我输入npm start时,它正在运行我的express应用程序。

但我希望浏览器同时打开http://localhost:8081。我怎么才能让start也打开我的本地url呢?

喜欢:"start": "node bin/www, http://localhost:8081"

因此,当我输入npm satrt时,它会运行我的express应用程序,同时打开url。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-02-08 10:34:11

据我所知,这就像是编写一个bash命令:

代码语言:javascript
复制
// Windows
"start":"start http://localhost:8081 & node bin/www"

// Mac
"start":"open http://localhost:8081 && node bin/www"

// Linux
"start":"xdg-open http://localhost:8081 && node bin/www"
票数 44
EN

Stack Overflow用户

发布于 2017-03-15 22:10:08

要获得跨平台支持,请使用open-cli

安装它:

代码语言:javascript
复制
npm install --save-dev open-cli

将其添加到脚本中:

代码语言:javascript
复制
"start": "open-cli http://localhost:8081 && node bin/www"
票数 21
EN

Stack Overflow用户

发布于 2017-07-26 10:44:51

您只需要以正确的顺序使用start

代码语言:javascript
复制
"start": "npm run dev & start http://localhost:8000",

坏的

代码语言:javascript
复制
"start": "start http://localhost:8000 & npm run dev",

好的

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35261535

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档