javascript - 运行 node.js 的问题

标签 javascript node.js

我是 node.js 的新手。我按照 Here 中的下载和安装说明进行操作.

现在当我在我的终端中尝试这个时出现问题

node

我收到以下消息

No script was specified.
Usage: node [options] script.js [arguments] 
Options:
  -v, --version      print node's version
  --debug[=port]     enable remote debugging via given TCP port
                     without stopping the execution
  --debug-brk[=port] as above, but break in script.js and
                     wait for remote debugger to connect
  --v8-options       print v8 command line options
  --vars             print various compiled-in variables

Enviromental variables:
NODE_PATH            ':'-separated list of directories
                     prefixed to the module search path,
                     require.paths.
NODE_DEBUG           Print additional debugging output.

Documentation can be found at http://nodejs.org/api.html or with 'man node'

之后我尝试了这个例子:

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');

它说:ReferenceError: console is not defined.

我用谷歌搜索了一下,发现我没有正确安装 nodejs,所以我重新安装了它,但没有成功:(

请帮忙!!

最佳答案

安装手册版本太旧

这样做

wget http://nodejs.org/dist/node-v0.4.6.tar.gz
gunzip node-v0.4.6.tar.gz
tar -xf node-v0.4.6.tar
cd node
./configure
make
sudo make install

顺便说一句,这里是官方安装说明:https://github.com/joyent/node/wiki/Installation

关于javascript - 运行 node.js 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5685244/

相关文章:

node.js - mongodb 中的多个组聚合

javascript - ";"怎么会是意外的token呢? ( react /巴别塔)

javascript - JSON 服务在 Angular JS 中不起作用

javascript - Safari 忽略 onclick 事件中的提交更改

javascript - 如何处理 ETIMEDOUT 错误?

node.js - 如果用户验证失败,在multer中停止文件上传

javascript - jQuery - 每 x 秒向下滚动一次,然后滚动到顶部

javascript - 如何删除逗号和命令?

node.js - 如何从 Mongodb 集合中分批获取文档以通过滚动到 React 进行加载

javascript - 无法从 'react/lib/React' 找到模块 'ReactTestUtils.js'