แนวคิดใดบ้างที่ฉันสามารถใช้การโหลดไฟล์อัตโนมัติใน Node.js ฉันเบื่อที่จะรีสตาร์ทเซิร์ฟเวอร์ทุกครั้งที่ฉันเปลี่ยนไฟล์ เห็นได้ชัดว่า Node.js 'require()
ฟังก์ชั่นว่าไม่ได้โหลดไฟล์ใหม่หากจำเป็นต้องใช้แล้วดังนั้นฉันต้องทำสิ่งนี้:
var sys = require('sys'),
http = require('http'),
posix = require('posix'),
json = require('./json');
var script_name = '/some/path/to/app.js';
this.app = require('./app').app;
process.watchFile(script_name, function(curr, prev){
posix.cat(script_name).addCallback(function(content){
process.compile( content, script_name );
});
});
http.createServer(this.app).listen( 8080 );
และในไฟล์app.jsฉันมี:
var file = require('./file');
this.app = function(req, res) {
file.serveFile( req, res, 'file.js');
}
แต่นี่ยังใช้งานไม่ได้ - ฉันได้รับข้อผิดพลาดในprocess.compile()
คำสั่งที่ระบุว่า 'ไม่จำเป็นต้องมี' process.compile
กำลังตรวจสอบapp.jsแต่ไม่มีเงื่อนงำเกี่ยวกับ node.js globals
Object.keys(require.cache).forEach(function(key) { delete require.cache[key]; });