---
title: "heroku部署nodejs+express"
author: "darklipeng"
date: "2012-01-22T13:58:03Z"
tags: ["heroku nodejs express"]
categories: ["编程语言"]
slug: "heroku-nodejs-express"
draft: false
lastmod: "2012-01-22T13:59:39Z"
id: 1370360
url: "https://darklipeng.iteye.com/blog/1370360"
---

1.下载安装

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

 

2.建工程

d:

cd nodejs

d:\\nodejs&gt;express shurrik-express

cd shur*

d:\\nodejs\\shurrik-express&gt;npm install

d:\\nodejs\\shurrik-express&gt;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&gt;git init

d:\\nodejs\\shurrik-express&gt;git add .

d:\\nodejs\\shurrik-express&gt;git commit -m 'init'

d:\\nodejs\\shurrik-express&gt;heroku create shurrik-express -- stack cedar

d:\\nodejs\\shurrik-express&gt;git push heroku master

d:\\nodejs\\shurrik-express&gt;heroku ps:scale web=1

效果：[http://shurrik-express.herokuapp.com/](http://shurrik-express.herokuapp.com/)

更多参见：[http://devcenter.heroku.com/articles/node-js](http://devcenter.heroku.com/articles/node-js)