Skip to content
Related Articles

Related Articles

How to change npm start script of node.js ?
  • Last Updated : 31 Mar, 2021

The script is a list of commands that are used to perform some specific tasks that they are designed to perform. In Node.js there are a lot of predefined scripts created while creating a new project some of them contain a default value, and we can also change them according to our need of the operations for a specific task. 

Script keywords available in node.js  are given below npm start script is one of the most commonly used scripts in the node.js as well as in react. npm start: npm start script is used to execute the defined file in it without typing its execution command.

Package.json file

"scripts"{
"start":"node index.js"
}

index.js






// Importing http module
const http = require("http")
  
// Creating Server
const server = http.createServer((req,res)=>{
    req.statusCode=200;
    console.log("Server is Started")
    res.end();
});
  
// Executing the server
server.listen(3000,"localhost",()=>{
    console.log("Server is Running ")
})

Run index.js file using below command:

node index.js

Output:

When no execution file mentioned in the npm start script npm automatically runs the node server.js file if available in the project directory.

package.json

server.js




// Importing http module
const http = require("http")
  
// Creating Server
const server = http.createServer((req,res)=>{
    req.statusCode=200;
    console.log("Server  is Executed")
    res.end();
});
  
// Executing the server
server.listen(3000,"localhost",()=>{
    console.log("This is server.js file")
})

Run server.js file using below command:

node server.js

Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :