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

Node.js程序在node-windows中不能运行的更多相关文章

  1. 玩儿转物联网IoT - 在Beagle Bone Black上运行node.js 程序

    物联网(IoT)技术方兴未艾,智能手环,智能血压计,智能眼镜甚至智能鞋垫都开始进入我们的生活,各种智能设备层出不穷,世界已经到了一个"人有多大胆,地有多大产"的时代,不玩儿点物联网 ...

  2. 在Visual Studio上开发Node.js程序(2)——远程调试及发布到Azure

    [题外话] 上次介绍了VS上开发Node.js的插件Node.js Tools for Visual Studio(NTVS),其提供了非常方便的开发和调试功能,当然很多情况下由于平台限制等原因需要在 ...

  3. 在Visual Studio上开发Node.js程序

    [题外话] 最近准备用Node.js做些东西,于是找找看能否有Visual Studio上的插件以方便开发.结果还真找到了一个,来自微软的Node.js Tools for Visual Studio ...

  4. 一种简单的生产环境部署Node.js程序方法

    最近在部署Node.js程序时,写了段简单的脚本,发觉还挺简单的,忍不住想与大家分享. 配置文件 首先,本地测试环境和生产环境的数据库连接这些配置信息是不一样的,需要将其分开为两个文件存储 到conf ...

  5. 在Visual Studio 2013 上开发Node.js程序

    [题外话] 最近准备用Node.js做些东西,于是找找看能否有Visual Studio上的插件以方便开发.结果还真找到了一个,来自微软的Node.js Tools for Visual Studio ...

  6. 使用events.EventEmitter 控制Node.js 程序执行流程

    使用events.EventEmitter 控制Node.js 程序执行流程 标题写的可能也不太对,大家领会精神: Node.js 是一个基于Chrome JavaScript 运行时建立的一个平台. ...

  7. node.js安装和配置(windows系统)

    node.js安装和配置(windows系统) node javasript vscode  node是javascript的管理工具,所以开发javasript项目都要下载安装和配置node. 传送 ...

  8. 调试 node.js 程序

    调试 node.js 程序 在程序开发中,如何快速的查找定位问题是一项非常重要的基本功.在实际开发过程中,或多或少都会遇到程序出现问题导致无法正常运行的情况,因此,调试代码就变成了一项无法避免的工作. ...

  9. 3.第一个Node.js程序:Hello World!

    转自:http://www.runoob.com/nodejs/nodejs-tutorial.html 以下是我们的第一个Node.js程序: console.log("Hello Wor ...

随机推荐

  1. 希尔排序之C++实现(高级版)

    希尔排序之C++实现(高级版) 一.源代码:ShellSortHigh.cpp /*希尔排序基本思想: 先取一个小于n的整数d1作为第一个增量,把文件的全部记录分组. 所有距离为d1的倍数的记录放在同 ...

  2. [BZOJ5338][TJOI2018]xor(可持久化Trie)

    可持久化Trie模板题. 建两种可持久化Trie,每个点两棵,一棵对DFS求前缀和,一棵对祖先求前缀和. 或者树剖,不好写多少还多个log. #include<cstdio> #inclu ...

  3. Java集合的ConcurrentModificationException

    简单复习一下集合顺带提一下这个错误,其实也比较常见,大多是因为疏忽的原因吧: 我们创建一个集合,添加了一些元素,使用迭代器来遍历,然后遍历途中需要进行一些逻辑操作,对集合进行修改,然后就报错了,这是什 ...

  4. phpunit Cannot redeclare class PHPUnit_Runner_Version

  5. PostgreSQL修改数据库目录/数据库目录迁移

    说明:以9+版本为例,10+的版本只要把目录替换一下即可.迁移目录肯定是要停服的! 1.在数据库软件安装之后,初始化数据库时候,可以指定初始化时创建的数据库的默认文件路径 /usr/local/pgs ...

  6. perf 工具介绍2

    [root@localhost ~]# cat test1.c void longa() { int i,j; ; i < ; i++) j=i; //am I silly or crazy? ...

  7. java基础学习总结——网络编程

    一.网络基础概念 首先理清一个概念:网络编程 != 网站编程,网络编程现在一般称为TCP/IP编程.

  8. jQuery异步获取json数据的2种方式

    jQuery异步获取json数据有2种方式,一个是$.getJSON方法,一个是$.ajax方法.本篇体验使用这2种方式异步获取json数据,然后追加到页面. 在根目录下创建data.json文件: ...

  9. Kali Linux下安装配置ProFTPD实例

    1.安装ProFTPD 在ftp://ftp.proftpd.org/下能够找到官方公布的各个ProFTPD版本号,本人使用ftp://ftp.proftpd.org/historic/source/ ...

  10. 页面中checkbox返回的是一个数组,如何对数组进行操作

    1. 仅仅利用javascript进行操作: //html代码如下: <form action="#" method="POST" onsubmit=&q ...