Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have this start params in package.json

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

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

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

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

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

like image 488
sreginogemoh Avatar asked Feb 08 '16 02:02

sreginogemoh


People also ask

What script does npm start run?

So npm start runs the node script that is listed under start in the package. json.

How do I start a website using npm?

Run npm install http-server --save-dev to have http-server as development dependency, which is able to serve the index. html file. In package. json add to the scripts the start npm script for starting of the http-server : "scripts": {"start": "http-server"} .

How do I run a script after npm install?

You can easily run scripts using npm by adding them to the "scripts" field in package. json and run them with npm run <script-name> . Run npm run to see available scripts. Binaries of locally install packages are made available in the PATH , so you can run them by name instead of pointing to node_modules/.

What is npm Run command?

npm run sets the NODE environment variable to the node executable with which npm is executed. If you try to run a script without having a node_modules directory and it fails, you will be given a warning to run npm install , just in case you've forgotten.


2 Answers

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" 
like image 156
tylerargo Avatar answered Sep 29 '22 06:09

tylerargo


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" 
like image 43
pomber Avatar answered Sep 29 '22 04:09

pomber