更改 Node.js 的 npm 启动脚本
Node.js 应用程序的启动脚本包含了执行特定任务所需的所有命令。在启动或初始化 Node.js 项目时,会创建许多预定义的脚本用于运行应用程序。可以根据项目的需要或需求更改这些脚本。
脚本命令广泛用于在 Node 和 React 中创建程序的不同启动脚本。“npm start”用于执行启动脚本,而无需键入其执行命令。
package.json 文件
这是需要添加到 package.json 文件中的启动脚本。此处的文件名是“index.js”。您可以根据需要更改此名称。
"scripts"{
"start":"node index.js" //Name of the file
}下面是一个展示启动脚本实现的示例。

示例 - sendStatus()
创建一个名为 index.js 的文件并复制下面的代码片段。创建文件后,使用以下命令运行此代码,如以下示例所示:
npm start
index.js
// 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
res.send(data);
})
// Setting up the server at port 3000
app.listen(3000 , ()=>{
console.log("server running");
});输出
C:\home
ode>> npm start
上述语句将自行运行 index.js 文件。此命令本身启动了项目的 main 类。
现在,从浏览器中访问以下 URL 以访问网页:https://:3000

广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP