您的位置:首页 > Web前端 > Node.js

mac平台下面nodejs环境搭配

2015-06-10 21:20 441 查看
方法一(pkg方式:下载链接http://nodejs.org/dist/v0.12.4/node-v0.12.4.pkg):

官网:https://nodejs.org/download/

例子:

he.js:

var http = require('http');
http.createServer(function(req, res){
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8808, '127.0.0.1');
console.log('Server running at ' target='_blank'>http://127.0.0.1:8808');[/code] 
启动:

adeMacBook-Pro:nodejs_dev apple$ node he.js
Server running at http://127.0.0.1:8808[/code] 


安装CouchDB

sudo brew install couchdb


下载教程:

git clone https://github.com/indexzero/nodejs-intro.git[/code] 
启动 CouchDB 数据库

sudo couchdb




验证:

访问:http://127.0.0.1:5984/_utils/



创建 CouchDB 数据库

adeMacBook-Pro:~ apple$ curl -X PUT http://127.0.0.1:5984/pinpoint-dev10 {"ok":true}


你可以在浏览器中访问 http://127.0.0.1:5984/_utils 就可以看到新创建的数据库。



开始教程:

node js 实例使用模块化的方式构建,lib 目录包含很多模块,而服务器脚本在 bin 目录下。

例如,我们要启动 CouchDB 教程,可以在 bin 目录下执行下面命令:

./server -t 02couchdb -s


其中 -t 参数允许你指定要执行的 lib 目录下的模块,-s 参数用以设置我们刚建立的 pinpoint-dev 数据库。



adeMacBook-Pro:nodejs-intro apple$ ./bin/server -t 02couchdb -s
util.puts: Use console.log instead
Hello node listening on http://127.0.0.1:8000[/code] 
安装http-console:

sudo npm install -g http-console


adeMacBook-Pro:~ apple$ http-console
> http-console 0.6.3
> Welcome, enter .help if you're lost.
> Connecting to 127.0.0.1 on port 8080.
 http://127.0.0.1:8080/> POST /bookmarks
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: