Node.js Application as a Windows Service (With registry fix) – Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

npm install

In my case, command nssm install MyWebService… was unsuccessful, the problem was that app.js can’t find config.json file.

First you will need:

  1. Node.js application (project) which you want to run as a Windows Service
  2. Node.js
  3. NSSM

1 step: Set your Node.js application as Windows Service

Download nssm.exe and put file into you node.js project folder

Put nssm.exe file into you node.js project folder

Run Windows Command Processor (cmd.exe) as administrator and go to your node.js project folder

Your node.js project folder

Run command npm install

npm install

Run command node src\app.js and allow access through Windows firewall

Allow access through Windows firewall

Run these two commands
nssm.exe install MyWebService "C:\Program Files\nodejs\node.exe" "C:\Service\src\app.js"
net start MyWebService

net start MyWebService

Now we need to fix this error.

2 step: Edit registry

Open registry editor (regedit.exe) and go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\MyWebService\Parameters

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\MyWebService\Parameters

Now we need to change AppDirectory from C:\Program Files\nodejs to C:\Service

Change AppDirectory from C:\Program Files\nodejs to C:\Service

Restart computer and don’t forget to run Apache, MySQL or any other necessary servers for your project after restart.

Node.js Application as a Windows Service

Share

package.json 里的依赖怎么写

Dependencies
可选字段,指示当前包所依赖的其他包。

{ “dependencies” :
{ “foo” : “1.0.0 – 2.9999.9999”
, “bar” : “>=1.0.2 <2.1.2”
, “baz” : “>1.0.2 <=2.3.4”
, “boo” : “2.0.1”
, “qux” : “<1.0.0 || >=2.3.1 <2.4.5 || >=2.5.2 <3.0.0”
, “asd” : “http://asdf.com/asdf.tar.gz”
, “til” : “~1.2”
, “elf” : “~1.2.3”
, “two” : “2.x”
, “thr” : “3.3.x”
}
}
版本格式可以是下面任一种:

version 完全匹配

version 大于这个版本
=version大于或等于这个版本
=version1 <=version2.
range1 || range2 满足任意一个即可
git… Git地址
user/repo
devDependencies
可选字段。如果只需要下载使用某些模块,而不下载这些模块的测试和文档框架,放在这个下面比较不错。

peerDependencies
可选字段。兼容性依赖。如果你的包是插件,适合这种方式。

bundledDependencies
可选字段。发布包时同时打包的其他依赖。

optionalDependencies
可选字段。如果你想在某些依赖即使没有找到,或则安装失败的情况下,npm都继续执行。那么这些依赖适合放在这里。

Share