PM2下使用 npm run 命令

2020-03-30 15:37:12

需求:

npm run xxxx 是 node常用的启动方式之一,本文介绍下如何用PM2来实现该方式的启动。

下面是项目的package.json文件部分代码:

  "scripts": {

    "dev": "node build/dev-server.js --env=local",

    "start": "node build/dev-server.js --env=local",

    "build": "node build/build.js --env=publish",

    "build-local": "node build/build.js"

  },

注意,下面两种方式是等效的:

1. npm run dev

2. pm2 start  npm -- run dev

语法:pm2 start npm --watch --name <taskname> -- run <scriptname>;

其中 -- watch监听代码变化,-- name重命名任务名称,-- run后面跟脚本名字

至此,PM2实现npm run 来启动 node 的方法已经实现。




  • 2017-11-06 01:00:17

    撤销git add

    如何撤销git add,不小心执行了git add . 操作,但是又不能提交所有的文件,因为对应不同的分支,现在怎么样可以将git add 撤销回来

  • 2017-11-10 00:06:15

    CORS: credentials mode is 'include'

    XMLHttpRequest cannot load http://localhost/Foo.API/token. The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://localhost:5000' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.