关于部署Node.js&的问题Socket.IO应用程序到Nodejitsu

时间:2013-05-29 17:11:29

标签: node.js socket.io nodejitsu

我是Node.js,Socket.IO和Nodejitsu的新手。我也在我的机器上运行Ubuntu。在谷歌搜索Node.js和Socket.IO的免费提升支持后,我找到了Nodejitsu托管平台。他们说部署应用程序很容易,但我发现它有点复杂。这是我遵循的流程。

在使用Nodejitsu设置我的帐户后,我跑了:

sudo npm install jitsu -g
sudo jitsu install socket.io

我尝试使用以下方式部署应用程序:

jitsu deploy

但我在cmd行上收到两条警告:

warn:    There is no package.json file in /home/ben
warn:    Creating package.json at /home/ben/package.json

并且jitsu正在提示:

prompt: Application name:  (ben) 
prompt: Subdomain name:  (cand-ben) 
prompt: scripts.start:

首先,我不明白这两个警告的用途是什么?我应该在那里创建一个package.json文件吗?我还尝试在提示符后的命令行中启动这样的脚本:scripts.start:

var http = require('http');
  http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('hello, i know nodejitsu\n');
}).listen(8080);

但我收到此错误消息

prompt:  scripts.start:  var http = require('http');
error:   Invalid input for scripts.start
error:   Start script was not found in /home/ben
prompt:  scripts.start:  http.createServer(function (req, res) {
error:   Invalid input for scripts.start
error:   Start script was not found in /home/ben
prompt:  scripts.start:      res.writeHead(200, {'Content-Type': 'text/plain'});
error:   Invalid input for scripts.start
error:   Start script was not found in /home/ben
prompt:  scripts.start:      res.end('hello, i know nodejitsu\n');
error:   Invalid input for scripts.start
error:   Start script was not found in /home/ben
prompt:  scripts.start:  }).listen(8080);

请告诉我如何将脚本传递到命令提示符?我应该如何创建package.json?是否有任何明确的教程说明这些东西?

由于

错误从Peter站点添加package.json后。

warn:    About to write /home/ben/package.json
data:    
data:    {
data:        engines: { node: '0.8.x' },
data:        name: 'ben',
data:        scripts: { start: '' },
data:        subdomain: 'candente-ben',
data:        version: '0.0.0'
data:    }
data:    
prompt: Is this ok?:  (yes) 
info:    Analyzing application dependencies in 
WARN package.json ben@0.0.0 No repository field.
WARN package.json ben@0.0.0 No readme data.
info:    Checking app availability ben
info:    Checking app availability ben
info:    Creating app ben
info:    Creating app ben
error:   Error creating ben
error:   Nodejitsu Error (500): Internal Server Error
error:   Error running command deploy
error:   Nodejitsu Error (500): Internal Server Error
warn:    Error returned from Nodejitsu
error:   Error: App name / subdomain combination is not available
error:       at module.exports    (/root/nodejitsu/lib/nodejitsu/resources/app/controller/available.js:27:17)
error:       at Resource._request (/root/nodejitsu/node_modules/resourceful/lib/resourceful/resource.js:184:13)
error:       at Function.Resource.runAfterHooks (/root/nodejitsu/node_modules/resourceful/lib/resourceful/resource.js:93:12)
error:       at Resource._request (/root/nodejitsu/node_modules/resourceful/lib/resourceful/resource.js:179:14)
error:       at Couchdb.view (/root/nodejitsu/node_modules/resourceful/lib/resourceful/engines/couchdb/index.js:143:5)
error:       at Request._onResponse [as _callback] (/root/nodejitsu/node_modules/resourceful/node_modules/cradle/lib/cradle.js:233:9)
error:       at Request.init.self.callback (/root/nodejitsu/node_modules/request/main.js:120:22)
error:       at Request.EventEmitter.emit (events.js:99:17)
error:       at Request.<anonymous> (/root/nodejitsu/node_modules/request/main.js:555:16)
error:       at Request.EventEmitter.emit (events.js:96:17)
help:    For help with this error contact Nodejitsu Support:
help:      webchat: <http://webchat.nodejitsu.com/>
help:          irc: <irc://chat.freenode.net/#nodejitsu>
help:        email: <support@nodejitsu.com>
help:    
help:      Copy and paste this output to a gist (http://gist.github.com/)
info:    Nodejitsu not ok

1 个答案:

答案 0 :(得分:3)

  

首先,我不明白这两个警告的用途是什么?我应该在那里创建一个package.json文件吗?

是。 nodejitsu部署需要package.json文件才能工作。它描述了应用程序运行所需的环境。

  

我还尝试在提示符后的命令行中启动这样的脚本:scripts.start:

scripts.start不能是javascript代码,它必须是一个简单的shell命令。获取该javascript代码并将其保存在名为server.js的文件中,然后将scripts.start命令设为node server.js

这是Nodejitsu的package.json file互动指南。当然official npm docs on package.json是必读的。如果要引用它,则部署在nodejitsu上的here is an open-source app I wrote。基本的scripts.start属性需要符合以下几行:

"scripts": {"start": "node server.js"}

更新

所以你可能在这里尝试了太多的东西,没有花足够的时间在基础上避免麻烦。不要跳过任何这些步骤。您将在此过程中学习和理解,并且您将能够自己理解未来的错误。

  • 首先,使用node server.js等手动命令让您的应用在本地运行。
  • 第二次,命令npm start通过让您的package.json正确在本地工作。
  • 第三次,然后努力使其在nodejitsu上运行。