当前位置: 代码迷 >> JavaScript >> heroku调度nodejs+express
  详细解决方案

heroku调度nodejs+express

热度:683   发布时间:2012-09-06 10:37:01.0
heroku部署nodejs+express

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
  相关解决方案