cloudfoundry.com 安装 nodejs笔记(一)

vmc push后  发现服务无法启动  

vmc logs  [servername]  也没发现有任何日志出现 页面出现的错误是

“VCAP ROUTER: 404 - DES” 

google了一下 发现是因为服务没有启动

应该还是我写的nodejs有问题,后来在这里

http://support.cloudfoundry.com/entries/20047352-node-js-helloworld-app-deploy-got-error-306-error-retrieving-file-logs-startup-log 

发现 原来cloudfoundry的服务器 在node里是不能指定他的端口号的,只能通过环境变量来取得对应的端口,

var http = require('http');

var url = require('url');

 

HOST = null;

 

var host = process.env.VCAP_APP_HOST || 'localhost';

var port = process.env.VCAP_APP_PORT || 3000

 

http.createServer(function (req, res) {

  res.writeHead(200, {'Content-Type': 'text/html'});

  res.write('<h1>Hello from the Cloud! ');

  res.write('via: ' + host + ':' + port);

  res.end('</h1>');

}).listen(port, null);

 

console.log('Server running at http://' + host + ':' + port + '/');

 注意 启动的js必须是app.js 这样才能被cloudfoundry系统识别 

经过上述代码,终于看到helloworld了。

 下一步查看怎样在cloudfoundry里面加载插件和使用数据库

参考下面的网页:

http://support.cloudfoundry.com/entries/505133-deploying-a-node-js-app-with-npm-dependencies 

 http://www.mihswat.com/2011/05/04/getting-started-with-cloud-foundry-using-a-node-js-and-mongodb-application/

posted @ 2011-11-09 17:38  方子尚  阅读(508)  评论(0编辑  收藏  举报