Changing the npm start-script of Node.js

Node.jsJavascriptWeb DevelopmentFront End Technology

The start-script of a Node.js application consists of all the commands that will be used to perform the specific tasks. When starting or initializing a Node.js project, there are a lot of predefined scripts that will be created for running the application. These scripts can be changed as per the need or demand of the project.

Script commands are widely used for making different startup scripts of programs in both Node and React. 'npm start' is used for executing a startup script without typing its execution command.

Package.json File

This is the start-up script that needs to be added in the package.json file. The name of the file here is 'index.js'. You can change this name as per your needs.

   "start":"node index.js" //Name of the file

Below is an illustartion showing the implmentation of startup script.

Example - sendStatus()

Create a file with name – index.js and copy the below code snippet. After creating the file, use the below command to run this code as shown in the example below −

npm start


// Importing the express module
const express = require('express');
const app = express();

// Initializing the data with the following string
var data = "Welcome to TutorialsPoint !"

// Sending the response for '/' path
app.get('/' , (req,res)=>{

   // Sending the data json text

// Setting up the server at port 3000
app.listen(3000 , ()=>{
   console.log("server running");


C:\home\node>> npm start

The above statement will itseld run the index.js file. This command itself starts the main class for the project.

Now hit the following URL from your browser to access the webpage – http://localhost:3000

Published on 20-May-2021 11:11:58