【发布时间】:2014-06-13 16:02:41
【问题描述】:
我在桌面上打开了一个文本文件。在我写的那个文件中
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
然后我保存了名为 example.js 的文件,当我输入 节点示例.js 打印此错误
Error: Cannot find module 'C:\Users\admin\Desktop\example.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
文件example.js在桌面上我做错了什么
【问题讨论】:
-
您的代码在 Mac 上为我工作。检查您的节点版本和文件权限等。你所拥有的看起来是正确的,看起来应该可以工作。
-
你能不能运行
node,然后输入require("./example.js");?在另一个目录中? -
@TruePS 您能否添加您如何解决它作为已接受的答案?或者,如果它是其他人不太可能遇到的微不足道的问题,则删除该问题。
-
@TruePS,您提到 example.js 在桌面上。在输入“node example.js”之前,您是否 cd 到桌面目录
-
可能是一个愚蠢的问题,但您的文件是实际的 JS 文件而不是 example.js.txt 吗?
标签: node.js