In this small tutorial we will learn how we use the “npm start” command in node.js.Let us create a simple node application using express framework:
npm install -g express-generator
cd mynodeapp/ && npm install // run this command if npm is not installed in the system
PORT=3000 npm start // 3000 is the default port for node.js applications
After running the above command on the terminal the project named “mynodeapp” gets created and will be listening on port 3000 . Now for running node application “mynodeapp” let us install nodemon . Nodemon will make sure if we have made any changes in our project files it will automatically restart our node application this will help us not to run the node command each time after we made the changes in any project file .
npm install -g nodemon
When we run the command npm start from the root directory of our node application, node checks the package.json file for scripts object. If scripts object is found, it checks for a script with the key start and run the command wirtten as a value for the key.