MEAN stack

0. Introduction

MEAN stack
– MongoDB
– Express : Javascript Web framework and add-ons – including Mongoose, an ORM for MongoDB
– Angular : Template
– Node : event-driven, server-side Javascript runtime – powered by the V8 engine

NPM : package manager

X. [nodejs v.s. npm] Around the bush Installation

To fix this error, we have to set the URL

Error: failed to fetch from registry:

use instead of

$ npm config set registry

NOTE : however, in ubuntu 12.04, nodejs and npm version is conflicted.

npm ERR! error installing express@3.4.4
npm ERR! error rolling back express@3.4.4 Error: UNKNOWN, unknown error '/media/disk-1/testnewfolder/node_modules/express'

npm ERR! Unsupported
npm ERR! Not compatible with your version of node/npm: connect@2.11.0
npm ERR! Required: {"node":">= 0.8.0"}
npm ERR! Actual:   {"npm":"1.1.4","node":"0.6.12"}

1. [nodejs and npm] Real Installation

On ubuntu 12.04, the launchpad repository gives conflict of npm and nodejs ( as in section X. )

Therefore, we need to add PPA following official nodejs documentation

$ curl --silent --location | sudo bash -
$ sudo apt-get install --yes nodejs

2. Express installation

npm usage : command line

Example : install express

 $ npm install express

The folder node_modules/express will be created

npm usage : install all dependencies using package.json


"name" : "MyStaticServer",
"version" : "0.0.1",
"dependencies" : {
"express" : "3.3.x"

Then run

 $ npm install

TIPS : install and add dependency to package.json

npm install --save

Run Express


var express = require('express'),
app = express();

app.use(express.static(__dirname + '/public'));

 $ node server.js

That is the file server that we can access image on, for example http://localhost:8080/my_image.png

Another express example : response send

var app = require('express')();
var http = require('http').Server(app);

app.get('/', function(req, res){
 res.send('<h1>Hello world</h1>');

http.listen(3000, function(){
 console.log('listening on *:3000');

NOTE : use app.get(‘*’, For page not found

Another : serving HTML

app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');

ref :

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s