尝试启动server.js时出现node.js错误
我试图在新版本的Ubuntu 11.04 64位上创build一个node.js服务器。 我可以远程访问系统,因为它是来自外部提供者的虚拟服务器。
我在“/ home”目录下创build了两个文件夹:“server”和“http”。 我在“server”文件夹中安装了node.js(v0.79-pre),然后安装了“npm”(1.1.18)。 喜欢这个:
sudo apt-get install git-core curl build-essential openssl libssl-dev git clone https://github.com/joyent/node.git && cd node ./configure make sudo make install curl http://npmjs.org/install.sh | sudo sh
完成后,我在“http”文件夹中创build了一个名为“server.js”的文件,如下所示:
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/html'}); res.write('It works'); res.end(); }).listen(8080); console.log('Serveur tourne sur http://xxxxx:8080/');
完成后,我把自己放在http文件夹上,如下所示:
cd /home/http
最后,启动服务器,如下所示:
node server.js
这是我得到的:
/home/http/server.js:1 require('http'); ^ node.js:256 throw e; // process.nextTick error, or 'error' event on first tick ^ SyntaxError: Unexpected token ILLEGAL at Module._compile (module.js:432:25) at Object..js (module.js:462:10) at Module.load (module.js:351:32) at Function._load (module.js:309:12) at module.js:482:10 at EventEmitter._tickCallback (node.js:245:11)
我究竟做错了什么?
请记住我正在发现shell的使用,并且从来没有和服务器混淆过。
谢谢。
你在任何地方使用错误的引号。 例如, require('http');
应该是require('http');
或require("http");
。
尝试更换
require('http');
同
require('http');
你有错别字尝试这个
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/html'}); res.write('It works'); res.end(); }).listen(8080); console.log('Serveur tourne sur http://xxxxx:8080/');
在这个使用之后工作正常,不是一个倒退
- passportjs LocalStrategy允许比默认的用户名和密码更多的参数吗?
- 如何在mongodb中获取子文档字段的不同值,
- 在不同的主机上build立套接字连接时出现'ECONNREFUSED'错误
- 在浏览器中通过WebCryptoAPI生成ECDH密钥,而不是浏览器化的节点密码模块
- 如何在使用NodeJS并保存到MongoDB时同步多个RESTFul请求?
- 这种MEAN堆栈devise模式适用于1,000-10,000个用户规模吗?
- 投射mp2tstream到Chromecast
- mongoose更新/ upsert?
- 在node.js中,如何声明一个可由主进程初始化并由工作进程访问的共享variables?