node.js npm "scripts": "start" 运行 express 并打开 url

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35261535/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 19:53:11  来源:igfitidea点击:

Npm "scripts": "start" run express and open url

node.jsangularexpressnpm

提问by sreginogemoh

I have this start params in package.json

我有这个开始参数 package.json

"scripts": {
    "start": "node bin/www"
  },

It is running my express app when I am typing npm start.

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

But I want browser opened http://localhost:8081at the same time. How can I say to startto open my local url as well?

但我希望浏览器同时打开http://localhost:8081。我怎么能说start打开我的本地网址呢?

like: "start": "node bin/www, http://localhost:8081"

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

So when I am typing npm satrtit runs my express app and opens the url at the same time.

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

回答by tylerargo

As far as I know it's like writing a bash command:

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

// 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"

回答by pomber

For cross-platform support use open-cli.

对于跨平台支持,请使用open-cli

Install it:

安装它:

npm install --save-dev open-cli

Add it to your scripts:

将其添加到您的脚本中:

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

回答by pomber

You just need to use startin the right order!

您只需要按start正确的顺序使用即可!

"start": "npm run dev & start http://localhost:8000",

Bad

坏的

"start": "start http://localhost:8000 & npm run dev",

Good

好的