Node.js栽倒在入门

usualregister 2012-03-22 03:34:09
我写的
hello.js var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Node.jsn');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');

运行 node hello.js 结果显示: ReferenceError:hello is not defined at repl:1:2 at ... ...
...全文
300 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
he_8134 2012-03-24
  • 打赏
  • 举报
回复
用node.exe,然后运行路径不要带中文字符。
比如,c:\新建文件件\hello.js 这样不行 c:\abc\hello.js 这样可以。
IT小金 2012-03-24
  • 打赏
  • 举报
回复
相对路径和绝对路径没学好!
usualregister 2012-03-23
  • 打赏
  • 举报
回复
$ node hello

node.js:116
throw e; // process.nextTick error, or 'error' event on first tick
^
ReferenceError: hello is not defined
at Object.<anonymous> (/home/Wang/node-v0.4.0/hello.js:1:63)
at Module._compile (module.js:373:26)
at Object..js (module.js:379:10)
at Module.load (module.js:305:31)
at Function._load (module.js:271:10)
at Array.<anonymous> (module.js:392:10)
at EventEmitter._tickCallback (node.js:108:26)
这是我用cygwin安装的,路径/home/Wang/node-v0.4.0/hello.js。。。。这是何故啊?
RainOnly 2012-03-23
  • 打赏
  • 举报
回复
错误很明白了已经 hello.js路径对不对
RainOnly 2012-03-23
  • 打赏
  • 举报
回复
... 不要总想着安装了就没事了啊. nodejs的编译是有路径限制的,路径不对就不行了.


先尝试用node.exe 跑跑js服务器再想想现在的情况吧... 明显是hello.js找不到
KK3K2005 2012-03-22
  • 打赏
  • 举报
回复
在什么环境下运行
hello.js的路径对不对

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧