#pragma section-numbers 3 == What is Node.js == Node.js is an application server based off of Google's V8 Javascript Engine. Quite a few popular frameworks have popped up around Node.js such as AngularJS and Backbone.js. == How == === Request a port === Request a !ProxiedServer port on bog as described in FirewallRules === Get Node.js === Make a directory for your website {{{ mcarberry@bog:~$ mkdir ~/public_web/sitename mcarberry@bog:~$ mkdir ~/public_web/sitename/nodejs mcarberry@bog:~$ cd ~/public_web/sitename }}} Download Node.js {{{ mcarberry@bog:~/public_web/sitename$ wget http://nodejs.org/dist/v0.10.26/node-v0.10.26.tar.gz mcarberry@bog:~/public_web/sitename$ tar -xf node-v0.10.26.tar.gz mcarberry@bog:~/public_web/sitename$ cd node-v0.10.26/ }}} === Build Node.js === {{{ mcarberry@bog:~/public_web/sitename/node-v0.10.26$ ./configure mcarberry@bog:~/public_web/sitename/node-v0.10.26$ make mcarberry@bog:~/public_web/sitename/node-v0.10.26$ make install DESTDIR=~/public_web/sitename/nodejs }}} Cleanup Install Directory {{{ mcarberry@bog:~/public_web/sitename/node-v0.10.26$ cd ../nodejs/ mcarberry@bog:~/public_web/sitename/nodejs$ cp -r usr/local/* . mcarberry@bog:~/public_web/sitename/nodejs$ rm -r usr mcarberry@bog:~/public_web/sitename/nodejs$ cd .. mcarberry@bog:~/public_web/sitename$ rm -r node-v0.10.26/ }}} === Test Install === Change the port in this script (gleaned from [[http://howtonode.org/how-to-install-nodejs|here]]) to the one requested in the firewall rules and place it in ~/public_web/sitename/. {{{#!highlight js var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Node.js\n'); }).listen(8124, "127.0.0.1"); console.log('Server running at http://127.0.0.1:8124/'); }}} Configure your domain, modelling [[DomTool/Examples#mod_proxy|this example]]. This will foward requests to your domain to the port that you requested on bog. Give it a test run {{{ mcarberry@bog:~/public_web/sitename$ ./nodejs/bin/node hello_world.js }}} If it works, when you visit your domain name you should see the Hello Node.js message. === Write a Script to Start the Server === Here's a script I use to start my Node.js server running Ghost. You'll need to use k5start (as I do) in order to make sure your server is able to maintain access to AFS. You should be able to modify this script to your needs with not too much effort. {{{#!highlight bash #!/bin/bash HOME=/afs/hcoop.net/user/m/mc/mcarberry GHOSTROOT=$HOME/public_web/ghost/ghost-app NODEROOT=$HOME/public_web/ghost/nodejs NODE=$NODEROOT/bin/node PIDFILE=$GHOSTROOT/ghost.pid K5START="k5start -qtUf /etc/keytabs/user.daemon/mcarberry" cd $GHOSTROOT NODE_CONFIG_DIR=$GHOSTROOT if (test -f $PIDFILE); then echo "PID File exists..." PID=`cat $PIDFILE 2> /dev/null` echo "Is previous server still running" kill -0 $PID 2> /dev/null if (test $? -ne 0); then echo "Nope, starting server" $K5START -b -c $PIDFILE -- $NODE $GHOSTROOT/index.js else echo "Yes, no need to start server" exit 0 fi else echo "Starting server" $K5START -b -c $PIDFILE -- $NODE $GHOSTROOT/index.js fi }}} === Add a Reboot Rule to Crontab === Request crontab access throught the portal, and set a rule such that your script will be run in the event of bog being rebooted.