Node.js程序在node-windows中不能运行

 

Node.js程序部分功能在命令行中运行良好,但在node-windows中不能运行,怎么回事?

答:路径问题。

请看如下的描述:

My script runs fine on it's own, but not with node-windows. Why?

The most common reason for this type of behavior is the configuration of a path. For example, a lot of people use __dirname to define a path within their script without understanding __dirname is a relative path. It can and often does differ between a child and parent process. As the documentation suggests, it is always best to use absolute paths, not relative paths. Remember that node-windows spawns your script as a new child process, which is why the working directory is different from when you run node myscript.js. This is not specific to node-windows, this is the context most Windows background services run in.

Another common issue is a misunderstanding of how a third party module is used within an app. Some modules make assumptions about the context in which they're running. Make sure you understand what your third party modules are doing, don't just use them blindly. Running a node script as a daemon is very different from running as a server or worker.

原文:https://github.com/coreybutler/node-windows/wiki#my-script-runs-fine-on-its-own-but-not-with-node-windows-why

你可能感兴趣的:(windows)