我是node.js世界的新手,我正在使用node.js v0.8.4。我用谷歌搜索了这个问题。是的,我得到了解决方案,但作为初学者仍然无法理解。所以请帮助我......
我正在学习 Node.js 教程。在该教程中使用了node.js v0.1.103,他写道
require.paths.unshift(__dirname+'/vendor');
var http = require('http'),
sys = require('sys'),
nodeStatic = require('node-static/lib/node-static');
var server = http.createServer(function(request, response) {
var file = new nodeStatic.Server('./public', function() {
cache: false
});
request.addListener('end', function() {
file.server(request, response);
});
}).listen(8000);
上面的脚本适合他。当我编写示例脚本并运行时,出现此错误。
C:\Documents and Settings\local>node C:\xampp\htdocs\rt\node\livestats\
server.js
Error: require.paths is removed. Use node_modules folders, or the NODE_PATH envi
ronment variable instead.
at Function.Module._compile.Object.defineProperty.get (module.js:386:11)
at Object.<anonymous> (C:\xampp\htdocs\rt\node\livestats\server.js:2:8)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
如何使 Node 从客户目录加载文件以及如何解决此问题?我的操作系统是windows
谢谢......
最佳答案
require.paths
很久以前就被弃用了。 Node v0.1 的教程现在几乎没用了,因为从那时起几乎一切都发生了变化。
如果您使用 npm install
安装了 node-static
,则只需使用 require("node-static")
即可,无需指定整个 Node 路径(当然,不使用 require.paths
)。
关于node.js - node.js require.paths.unshift() 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11774915/