我永远使用这个upstart脚本启动我的nodejs应用程序,它工作正常。问题是,当应用程序以编程方式创建文件夹时,它会在根目录上创建;
/ public / newfolder ,而不是/ var / www / nodeapp / public / newfolder 。
这是我的upstar文件myapp.conf:
#!upstart
#
description "Example upstart script for a Node.js process"
start on startup
stop on shutdown
expect fork
env NODE_BIN_DIR="/usr/bin"
env NODE_PATH="/usr/lib/node_modules"
env APPLICATION_PATH="/var/www/nodeapp/app.js"
env PIDFILE="/var/run/myapp.pid"
env LOG="/var/log/myapp.log"
env MIN_UPTIME="5000"
env SPIN_SLEEP_TIME="2000"
script
# Add the node executables to the path, which includes Forever if it is
# installed globally, which it should be.
PATH=$NODE_BIN_DIR:$PATH
exec forever \
--pidFile $PIDFILE \
-a \
-l $LOG \
--minUptime $MIN_UPTIME \
--spinSleepTime $SPIN_SLEEP_TIME \
start $APPLICATION_PATH
end script
pre-stop script
# Add the node executables to the path.
PATH=$NODE_BIN_DIR:$PATH
exec forever stop $APPLICATION_PATH
end script
和创建文件夹的api.js:
newFolder = "public/"+folder_ID; //relative path for new folder
var mkdirp = require('mkdirp');
mkdirp(newFolder, function(err) {
if (err){
console.log('error');
}else{
console.log('new folder');
}
});
我希望你能帮助我,谢谢。