我认为npm install|update
在需要源文件中的依赖项时有效,但是当我想运行可执行文件时,例如nodemon
,它似乎不起作用。它是否试图在全局范围内查找文件?我怎样才能让这些命令先看node_modules
?
我有一个 Cakefile,它用nodemon
. 例如:
# **`procExec(procName)`**
# returns the path to executable in `node_`
procExec = (procName) ->
console.log "./node_modules/" + procName + "/bin/" + procName
"./node_modules/.bin/" + procName
# **`cake startdev`**
# Starts the server with `nodemon`
# Watch and compile `.coffee` and `.styl` files in `/client`
task "startdev", "Starts server with nodemon and watch files for changes", ->
# start nodemon server
nodemon = spawn procExec("nodemon"), ["server.coffee"]
processOutput nodemon
# watch and compile CoffeeScript
coffee = spawn procExec("coffee"), ["-o", "public/js/app", "-cw", "client/coffee"]
processOutput coffee
# watch and compile Stylus
stylus = spawn procExec("stylus"), ["client/stylus", "-l", "-w", "-o", "public/css/app"]
processOutput stylus
它可以工作,但有一些小问题:
npm install|update
好像没有安装nodemon
。我认为它尝试全局安装并失败。我手动做了一个npm install nodemon
单独的。为什么是这样?我怎么能告诉nodemon
安装呢?"./node_modules/.bin/" + procName
总是解析为正确的可执行文件吗?