0
我想在啓動時從cron運行腳本;我見過很多關於路徑變量的參考,但沒有一個幫助我的情況。運行時,從cron運行node.js腳本失敗,手動工作正常
#!/bin/bash
cd /home/pi/Public/abc/
source $HOME/.profile
NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
sleep 2
nodemon app.js </dev/null>/home/pi/startup.log 2>/home/pi/startup.err &
請注意,我用相對和絕對路徑的每個組合
以下是錯誤日誌(:
這個cron:
@reboot /home/pi/nodestart.sh
這裏是腳本來自cron):
[email protected]:~ $ cat startup.err
module.js:471
throw err;
^
Error: Cannot find module 'sugar'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/pi/Public/abc/logutil.js:3:17)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
似乎找到如下圖所示其他模塊:
//app.js
var express = require('express');
var logger = require('tracer').colorConsole();
var fs = require('fs');
var multer = require('multer');
var app = express();
var async = require('async');
var bodyParser = require('body-parser');
var ejs = require('ejs');
const clientSessions = require("client-sessions");
var db = require('./dbutil');
var log = require('./logutil');
var passThru = require('stream').PassThrough;
var Sugar = require('sugar');
什麼想法?
模塊是如何安裝的?糖是全球安裝嗎? – akaphenom
全球,很抱歉! sudo npm安裝sugar -g – phpmydev
什麼是NodeJs的路徑 – akaphenom