Title: NodeJS and NPM install and intro to AngularJS
Date: 2014-04-03 00:00
[TOC]
## Install NodeJS and NPM
### Ubuntu NodeJS Packages
apt-get update; apt-get install nodejs npm`
nodejs --version
v0.10.25
which nodejs
/usr/bin/nodejs
`which node`
> So pretty useless... Instead:
1. cd /opt
1. wget http://nodejs.org/dist/v0.10.33/node-v0.10.33-linux-x64.tar.gz
1. tar -xf node-v0.10.33-linux-x64.tar.gz
1. ln -s /opt/node-v0.10.33-linux-x64/bin/node /usr/bin/node
WTF: get the latest npm 2.0 using: npm -g install npm@2
npm --version
npm config --list
### Source
1. sudo apt-get install build-essential libssl-dev
1. cd /opt
1. wget http://nodejs.org/dist/v0.10.33/node-v0.10.33-linux-x64.tar.gz
1. tar -xf node-v0.10.33-linux-x64.tar.gz
1. ./configure
1. make
1. sudo make install
`node-v0.10.26-linux-x64/bin/npm --version`
# 1.4.3
npm --version # 1.3.11
- - -
// global and require is per module
- - -
vi helloworld.js
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8124);
console.log('Server running at http://127.0.0.1:8124/');
node helloworld.js # node framework to run
- - -
vi info.js
var os = require( 'os' );
var http = require('http');
var helloworld = function( request, response ) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write( __filename + '\n' );
response.write( __dirname + '\n' );
response.end('Hello World\n');
};
http.createServer( helloworld ).listen( 8124 );
console.log( 'loading file:' + __filename + ' from directory ' + __dirname );
console.log( os.tmpdir() );
console.log( os.hostname() );
console.log( os.type() );
console.log( os.platform() );
console.log( os.arch() );
console.log( os.release() );
console.log( os.uptime() );
console.log( os.totalmem() );
console.log( os.freemem() );
console.log( os.cpus() );
console.log( os.networkInterfaces() );
console.log( 'Server running at http://127.0.0.1:8124/' );
- - -