Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to install node.js and CouchDB on a Google Compute Engine instance

#How to install node.js and CouchDB on a Google Compute Engine instance

Start and ssh into instance

Make sure you have a Google Compute engine account, have a project created and the gcutil command line tool installed.

Since want to ssh without the gcutil tool, you need to a your ssh key to the instance in addition to the already existing google_compute_engine key (used for gcutil).

cd $HOME/.ssh
gcutil addinstance --project=<project id> <instance name>,

Select region, select instance type, use persistance boot disc, use debian 7.

gcutil ssh --project=<project id> <instance name>

Install node.js

sudo apt-get install python g++ make checkinstall
mkdir ~/src && cd $_
wget -N
tar xzvf node-latest.tar.gz && cd node-v*
sudo checkinstall

In the dialog remove the "v" in front of the version number.

Test it:

> 1+1

Install CouchDB

sudo apt-get install couchdb
sudo couchdb

To access Couch on your local machine you need to create a tunnel. Get external IP of instance with gcutil getinstance --project=<project id> <instance name>

ssh -L 5984: <external ip of instance>

Create node app

sudo mkdir /var/www/mydomain
cd /var/www/mydomain
sudo nano app.js

Copy, paste and save:

var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
}).listen(3000, "");
console.log('Server running at');

Install and config nginx

sudo apt-get install nginx
cd /etc/nginx/sites-available
sudo nano

Copy, paste and save:

server {
  listen 80;
  server_name mydomain;
  access_log /var/log/nginx/yourdomain.log;

  # pass the request to the node.js server with the correct headers and much more can be added, see nginx config options
  location / {
sudo ln -s mydomain /etc/nginx/sites-enabled/
sudo /etc/init.d/nginx restart

Start node app

sudo npm install -g forever
forever start /var/www/mydomain/app.js
# to kill
# forever list
# forever stop 0 (for example)


Open external IP of instance (find it gcutil getinstance --project=<project id> <instance name>) in browser.


Installing node
Node and nginx
Setup Ghost with nginx on Debian
Google Compute Engine - Instances and Networks
Google Compute Engine - Connecting to an Instance Using ssh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.