如何使用Nodemon执行启动脚本?

时间:2022-04-03 23:15:47

How can I execute the start script from a package.json file with nodemon?

如何使用nodemon从package.json文件执行启动脚本?

6 个解决方案

#1


30  

This will be simple command for this

这将是一个简单的命令

nodemon --exec npm start

#2


11  

In package json:

在包json中:

{
  "name": "abc",
  "version": "0.0.1",
  "description": "my server",
  "scripts": {
    "start": "nodemon my_file.js"
  },
  "devDependencies": {
    "nodemon": "~1.3.8",
  },
  "dependencies": {

  }
}

Then from the terminal you can use npm start

然后从终端你可以使用npm start

Nodemon installation: https://www.npmjs.com/package/nodemon

Nodemon安装:https://www.npmjs.com/package/nodemon

#3


5  

I have a typescript file called "server.ts", The following npm scripts configures nodemon and npm to start my app and monitor for any changes on typescript files:

我有一个名为“server.ts”的打字稿文件,以下npm脚本配置nodemon和npm以启动我的应用程序并监视打字稿文件的任何更改:

"start": "nodemon -e ts  --exec \"npm run myapp\"", 
"myapp": "tsc -p . && node server.js",

I already have nodemon on dependencies, when I run npm start it will ask nodemon to monitor ts files using the -e switch and then it calls myapp npm script which is a simple combination of transpiling the typescript files and then starting the resulting server.js. When I change the typescript file, because of -e switch the same cycle happens and new js files will be generated and executed.

我已经有依赖关系的nodemon,当我运行npm start时,它会要求nodemon使用-e开关监视ts文件,然后调用myapp npm脚本,这是一个简单的组合,可以转换typescript文件,然后启动生成的server.js 。当我更改typescript文件时,由于-e开关会发生相同的循环,并且将生成并执行新的js文件。

#4


2  

Use -exec :

使用-exec:

"your-script-name": "nodemon [options] --exec 'npm start -s'"

#5


1  

Nodemon emits events upon every change in state; start, restart crash etc. You can add a nodemon configuration file (nodemon.json) like so:

Nodemon在每次状态变化时发出事件;启动,重启崩溃等。你可以像这样添加一个nodemon配置文件(nodemon.json):

{
   "events": {
       "start": "npm run *your_file*"
   }
}

Read more here: https://medium.com/netscape/nodemon-events-run-tasks-at-server-start-restart-crash-exit-93a34c54dfd8

在这里阅读更多内容:https://medium.com/netscape/nodemon-events-run-tasks-at-server-start-restart-crash-exit-93a34c54dfd8

#6


1  

first change your package.json file.

首先更改你的package.json文件。

"scripts":
 { "start": "node ./bin/www", 
"start-dev": "nodemon ./app.js"
 },

after that execute command npm run start-dev

之后执行命令npm run start-dev

#1


30  

This will be simple command for this

这将是一个简单的命令

nodemon --exec npm start

#2


11  

In package json:

在包json中:

{
  "name": "abc",
  "version": "0.0.1",
  "description": "my server",
  "scripts": {
    "start": "nodemon my_file.js"
  },
  "devDependencies": {
    "nodemon": "~1.3.8",
  },
  "dependencies": {

  }
}

Then from the terminal you can use npm start

然后从终端你可以使用npm start

Nodemon installation: https://www.npmjs.com/package/nodemon

Nodemon安装:https://www.npmjs.com/package/nodemon

#3


5  

I have a typescript file called "server.ts", The following npm scripts configures nodemon and npm to start my app and monitor for any changes on typescript files:

我有一个名为“server.ts”的打字稿文件,以下npm脚本配置nodemon和npm以启动我的应用程序并监视打字稿文件的任何更改:

"start": "nodemon -e ts  --exec \"npm run myapp\"", 
"myapp": "tsc -p . && node server.js",

I already have nodemon on dependencies, when I run npm start it will ask nodemon to monitor ts files using the -e switch and then it calls myapp npm script which is a simple combination of transpiling the typescript files and then starting the resulting server.js. When I change the typescript file, because of -e switch the same cycle happens and new js files will be generated and executed.

我已经有依赖关系的nodemon,当我运行npm start时,它会要求nodemon使用-e开关监视ts文件,然后调用myapp npm脚本,这是一个简单的组合,可以转换typescript文件,然后启动生成的server.js 。当我更改typescript文件时,由于-e开关会发生相同的循环,并且将生成并执行新的js文件。

#4


2  

Use -exec :

使用-exec:

"your-script-name": "nodemon [options] --exec 'npm start -s'"

#5


1  

Nodemon emits events upon every change in state; start, restart crash etc. You can add a nodemon configuration file (nodemon.json) like so:

Nodemon在每次状态变化时发出事件;启动,重启崩溃等。你可以像这样添加一个nodemon配置文件(nodemon.json):

{
   "events": {
       "start": "npm run *your_file*"
   }
}

Read more here: https://medium.com/netscape/nodemon-events-run-tasks-at-server-start-restart-crash-exit-93a34c54dfd8

在这里阅读更多内容:https://medium.com/netscape/nodemon-events-run-tasks-at-server-start-restart-crash-exit-93a34c54dfd8

#6


1  

first change your package.json file.

首先更改你的package.json文件。

"scripts":
 { "start": "node ./bin/www", 
"start-dev": "nodemon ./app.js"
 },

after that execute command npm run start-dev

之后执行命令npm run start-dev