Sergino
Sergino

Reputation: 10818

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

I have this entry in package.json

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

It runs my Express app when I enter the command npm start.

But I also want a browser to open http://localhost:8081 at the same time.

Something like:

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

So when I type npm start, it both runs my Express app and opens the URL.

Upvotes: 39

Views: 34325

Answers (3)

user8202629
user8202629

Reputation:

You just need to use start in the right order!

Incorrect:

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

Correct:

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

Upvotes: -1

pomber
pomber

Reputation: 23980

For cross-platform support use open-cli.

Install it:

npm install --save-dev open-cli

Add it to your scripts:

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

Upvotes: 24

tylerargo
tylerargo

Reputation: 1010

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

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

Upvotes: 49

Related Questions