ITeye博客

heroku部署nodejs+express

darklipeng · 2012-01-22 13:58 · nodejs · 编程语言 · heroku nodejs express · Markdown

1.下载安装

我下载的是windows版本:http://toolbelt.herokuapp.com/windows/download

 

2.建工程

d:

cd nodejs

d:\nodejs>express shurrik-express

cd shur*

d:\nodejs\shurrik-express>npm install

d:\nodejs\shurrik-express>node app.js

查看localhost:3000,应该能看到默认页面

 

3.修改

1)在app.js中修改端口号(heroku启动端口不是3000)

 

var port = process.env.PORT || 3000;

app.listen(port, function() {

  console.log("Listening on " + port);

});

//app.listen(3000);

//console.log("Express server listening on port %d in %s mode", app.address().port,app.settings.env);

2)添加启动文件Procfile

内容为下:

 

// Procfile

web: node app.js

 

4.上传部署

 

d:\nodejs\shurrik-express>git init

d:\nodejs\shurrik-express>git add .

d:\nodejs\shurrik-express>git commit -m 'init'

d:\nodejs\shurrik-express>heroku create shurrik-express -- stack cedar

d:\nodejs\shurrik-express>git push heroku master

d:\nodejs\shurrik-express>heroku ps:scale web=1

效果:http://shurrik-express.herokuapp.com/

更多参见:http://devcenter.heroku.com/articles/node-js

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。