用Node.js将Hello World部署到VPS上

可以跳过Node.js的安装。

苹果

brew install nodejs

乌班图

sudo apt-get install nodejs
sudo apt-get install npm

用Node.js编写一个Hello World。

var http = require('http');

var server = http.createServer(function( request, response){
    response.writeHead(200, {'Content-Type': 'text/plain'});
    response.end("Hello World\n");
});

server.listen(8000);

console.log("Server running at http://localhost:8000/");

尝试移动一下

node hello.js

在浏览器中打开localhost:8000,应该能看到hello world!非常简单。

飞行计划

服务器

安装forever来进行daemon化。

npm install -g forever

当地的

安装航班计划

npm install -g flightplan

配置文件

// flightplan.js
var appName = 'sample-node-app';
var username = 'yourusername'
var plan = require('flightplan');

// configuration
plan.target('staging', {
  host: 'yourdomain.com',
  port: <your ssh port>,
  username: username,
  agent: process.env.SSH_AUTH_SOCK
});

plan.target('production', [
  {
    host: 'yourdomain.com',
    port: <your ssh port>,
    username: username,
    agent: process.env.SSH_AUTH_SOCK
  }
]);

部署

fly production