【发布时间】:2014-09-03 17:36:14
【问题描述】:
我是学习 node.js 的新手,我在 ubuntu 上下载了所有组件。我写了一个测试,helloworld 应用程序,但由于某种原因它不起作用。这是我的文件布局。
当我执行哪个nodejs时,终端返回/usr/bin/nodejs
当我执行 which npm 时,终端返回 /usr/bin/npm
我的 app.js 测试文件位于 /home/tarang/node/helloWorld
这里是 app.js 的源代码
//creating http server
var http = require('require');
http.createServer(function(req, res){
res.writeHead(200, {'Context-Type': 'text/plain'});
res.end('helloWorld');
}).listen(8000);
console.log('server running');
更新
当我执行 nodejs app.js 时,我得到以下错误
Error: Cannot find module 'require'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/tarang/node/helloWorld/app.js:4:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
请解释一下,因为我是 ubuntu 和 nodejs 的新手。
谢谢!
更新
我需要更新到最新版本的 express、node 和 npm 吗?
【问题讨论】:
-
刚刚更新。请看一看!
标签: javascript node.js ubuntu