Node.JS is javascript running outside of your browser allowing you to access your machine/etc.


Express framework can be used build web site.


Command

Description

node -vDisplay version
nodeRun Node interpreter

node <file>

Run javascript file



Special Node.JS Javascript functions/objects

Command

Description

processShow program process


var m2 = require('./module2');Loads file module2 in current directory
console.log(m2);Write to console
module.exports.a=aExport variable a


Npm

Command

Description

npm install <module>

Will install module to your node_modules folder

You can then use it in your script by using:

var _ = require('underscrore');


npm initCreates a package.json for your project listing dependencies that were installed.
npm install <package> -SAdd package and add it to the package.json file



Basic Web Server Example

var http = require('http');
var server = http.createServer(function(request,response){
  console.log('got a request');
  response.write('hi');
  response.end();
});
server.listen(3000);


Express.JS

Create an Express

> npm install -g express-generator

> express <app_name>

> cd <app_name> && npm install

> DEBUG=<app_name> ./bin/www

Your app is now running on http://localhost:3000/






  • No labels