NodeJS in 5 minutes

Download Mac Installer
http://nodejs.org

Install and note that node was installed at

/usr/local/bin/node

npm (Node Package Manager)  was installed at
/usr/local/bin/npm

Make sure that /usr/local/bin is in your $PATH.

echo $PATH

Use npm to install node.js packages. This will install package XYZ in current directory

npm install XYZ

This will install package XYZ globally

npm install -g XYZ

Install driver/mapping for MongoDB

npm install mongoose

install rest library

npm install restify

Put your .js files in a Site directory and run them:

node myserver.js

Here is an example from the Node site

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

save this file in your Sites directory as example.js and run the node server

node example.js

Now open the path to the server in a browser

http://127.0.0.1:1337/

Advertisements
  • Calendar

    • September 2017
      M T W T F S S
      « Dec    
       123
      45678910
      11121314151617
      18192021222324
      252627282930  
  • Search