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.
So npm start runs the node script that is listed under start in the package. json.
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"} .
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/.
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.
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"
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With