Quick And Simple NodeJS Setup

less than 1 minute read

Getting up and running with Node is pretty simple.  Here's a quick script (with the largest part of help from here) to move things along that little bit quicker.  This isn't the best way if you want to stay up to date with releases, this will just get Node installed and ready to play
#! /bin/bash
### ###
# This script assumes you're kicking things off from a clean install of Ubuntu #
# You're welcome to skip parts which you've already installed! #
### ###
# Required - install curl
sudo apt-get install curl
# Optional - install libssl for ssl support
sudo apt-get install libssl-dev
# Get Node and build
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
# Add '--without-ssl' if not compiling with ssl support to avoid errors
./configure --prefix=~/local
make install
# Optional - install NPM (it'll make your life with node much easier!)
curl http://npmjs.org/install.sh | sh
# Optional - install Express (a great module to ease server creation)
npm install express
### ###
# That's it, go Node! #
### ###
/*
* With Node installed here's the classic Express server
*/
var app = require('express').createServer();
app.get('/', function(req, res){
res.send('Hello World');
});
app.listen(3000);
// run this with
// node express_server_sample.js
// visit http://localhost:3000 in your browser

Tags:

Updated:

Leave a Comment

Your email address will not be published. Required fields are marked *

Loading...