Thursday, January 29, 2015

Installing Express.js on Ubuntu

Environment


  • node.js 0.10.33
  • npm 2.3.0
  • express 2.3.0
  • Ubuntu 14.10
    • running on VirtualBox 4.3.20



Installing Express

Express is a node.js web application framework.

Express can be installed using the npm command from the last section.
craig@U14BASEBIG01:~$ sudo npm install express-generator -g
[sudo] password for craig:   
/usr/bin/express -> /usr/lib/node_modules/express-generator/bin/express  
express-generator@4.11.2 /usr/lib/node_modules/express-generator  
├── sorted-object@1.0.0  
├── commander@2.6.0  
└── mkdirp@0.5.0 (minimist@0.0.8)  
craig@U14BASEBIG01:~$ express --version  
4.11.2

Note the use of "sudo" to permit npm to write to the /usr/lib folder.  Also note the use of "express-generator" as the package being installed, rather than simply "express".  This seems contrary to almost every tutorial and piece of documentation (official or otherwise) that I've seen, but that's what worked for me.


Using NPM


NPM is the package manager for Node.

I can search NPM for modules to use in my code:
 craig@U14BASEBIG01:~$ npm search async  
 NAME                   DESCRIPTION                         AUTHOR        DATE    VERSION   KEYWORDS                                                                                 
 2way-router               2-way router                         =nyakto       2014-12-11 1.3.0    router two-way async promises                                                                      
 39f-callbacks              Async callback generator, designed to use with 39f-*…    =39dotyt       2014-08-16 1.0.0    callbacks 39 39-framework 39f                                                                      
 a-object                 A Node.js module for iterating through objects…       =fschuetz04     2015-01-01 1.0.4    asynchronous object synchronous update key value compare iterate                                                     
 a-promise                A lightweight Promise-like implementation for NodeJS     =steelbrain     2015-01-23 0.0.2    promise es6 async flow-control                                                                      
 a-sync                  Make sync functions a?sync                  =fritx        2014-06-07 0.0.0    sync async nodeify                                                                            
 aa                    Async-Await. co, co-chan, co-thunkify package        =lightspeedc     2014-04-05 0.0.4    chan co co-chan co-thunkify go channel aa async async-await                                                       
 aap                   async-await package                     =piscisaureus    2014-08-12 0.0.1                                                                                        
 abiogenesis               Asyncronous, nested 'task' runner framework with dependency… =jakeluer      2012-10-12 0.5.0                                                                                        
 ablock                  Asynchronous block-based templating             =jongleberry     2013-10-02 0.1.1                                                                                        
 accumasync                accumulate values asynchronously               =bumblehead     2014-04-18 0.0.2    loop async asynchronous accumulate                                                                    
 achain.js                A simple module to chain asynchronous calls.         =mattiasrunge    2014-06-12 0.0.8                                                                                        
 acomb                  Higher-order utilities for use with async functions     =aearly       2014-12-11 1.1.0    async combinators functional callbacks pointfree                                                             
 actor                  Experimental library implementing scala like actors in…   =gozala       prehistoric 0.0.2    actor generators async javascript 1.7                                                                  
 addon-storage              Async Firefox add-on json storage              =erikvold      2014-10-25 0.0.2    jetpack storage json firefox mozilla erikvold async jetpack-labs                                                     
 advisable                Functional mixin for sync and async before/after/around…   =slloyd       2012-09-02 0.2.0    advice AOP functional mixin                                                                       
 aegis                  Asynchronous lazy streams for everynyan.           =killdream      2014-12-11 0.1.0                                                                                        
 aejs                   Asynchroneous Embedded JavaScript Templates         =m1rr0r       2011-04-29 0.2.1    async template engine ejs                                                                        
 aemitter                 async emitter                        =mattmueller     2014-09-20 0.0.1                                                                                        
 aflow                  async flow control for calls with callbacks         =andrasq       2014-10-28 0.2.3    Andras quick flow control async                                                                     
 aflow.js                 Collection of async flow control methods.          =jaridmargolin    2014-11-11 0.0.2                                                                                        
 after-all                Execute several async functions and get a callback when…   =sorribas      2014-08-29 2.0.1                                                                                        
 after-all-results            Bundle results of async functions calls into one callback…  =watson       2014-08-16 1.1.0    parallel callback async done                                                                       
 after-sequence              Run several async functions and run a callback when they…  =sorribas      2014-11-27 1.0.0    sequence async series                                                                          
 aitch                  Toolkit for constructing hypertext service clients.     =novemberborn    2014-06-10 1.0.1    promise promises Promises/A+ promises-aplus deferred deferreds when future async asynchronous http request client legendary aitch                    
 aja                   Asynchronous JavaScript And JavaScript/JSON(P) : Ajax…    =krampstudio     2015-01-22 0.3.3    ajax xhr aja ajajs json jsonp                                                                      
 ajaja                  An Asynchronous Javascript and JSON library.         =andyburke      2014-11-04 0.1.1    ajaja ajaj ajax xhr                                                                           
 ajector                 Asynchronous dependency injector               =nailgun       2013-11-21 2.1.0    di dependency injector injection asynchronous                                                              
 ajs                   Experimental asyncronous templating in Node         =kainosnoema     2011-06-08 0.0.4    ajs ejs template view asyncronous                                                                    
 ajsh                   asynchronous jasmine specification helper          =dgf         2013-10-21 0.1.0                                                                                        
 ake                   A build tool                         =ngn         2013-03-26 0.0.9    build nodejs asynchronous continuation-passing style                                                           
 akeypair                 Async generate a RSA PEM key pair and self-signed cert…   =quartzjer      2014-12-05 0.2.4    rsa keypair keys encryption public private key pem x509 self-signed cert https tls certificate                                      
 aktualnivozy-api             Node.js promise based wrapper over AktualniVozy API.     =ondrs        2014-06-07 0.2.4    aktualnivozy api wrapper async promise                                                                  
 alagator                 Write algorithms that can be re-used for synchronous and…  =forbeslindesay   2013-06-28 1.0.0    promises promises-A promises-aplus async asynchronous sync synchronous ES6 yield generators harmony await                                
 alinex-config              Loading configuration files from different formats…     =alinex       2014-12-30 0.3.4    configuration parsing loading setup                                                                   
 allo                   Async functions to deal with race conditions         =couto        2014-06-23 0.1.0    async race conditions                                                                          
 am                    Data Dependence Async Module System(empty! preserved for…  =jin_preserved    2012-10-06 0.1.0                                                                                        
 am2315                  Simple async AM2315 Temp and Humidity Sensor library for…  =begizi       2014-01-03 1.0.3    am2315 raspi i2c temp humidity sensor                                                                  
 amanda                  JSON Schema validator                    =baggz =tu1ly…    2015-01-23 0.5.1    JSON JSON Schema schema validator validate JSON validator schema validator async browser                                         
 ambi                   Execute a function ambidextrously (normalizes the…      =balupton      2014-05-07 2.2.0    sync async fire exec execute ambidextrous flow                                                              
 amd                   Async Module Definition - module loader/bunder for node +…  =dominictarr     2011-05-29 0.0.0                                                                                        
 AMD                   AMD (Asynchronous Module Definition) support for node.js,…  =crabdude      2011-07-26 0.0.3    amd define module                                                                            
 amd-cli                 Diagnostic utilities for projects using the Asynchronous…  =zship        2014-08-16 2.3.0    amd diagnostic cli                                                                            
 amd-loader                Add the capability to load AMD (Asynchronous Module…     =fjakobs       2013-08-01 0.0.5                                                                                        
 amd-require               Add the capability to load AMD (Asynchronous Module…     =wiktor-k      2013-12-27 0.0.5                                                                                        
 amdtools                 Tools for Asynchronous Module Dispatch            =richardhodgson   2011-10-23 0.1.1                                                                                        
 amen                   A simple test suite for use with promises and generators   =dyoder       2014-11-03 1.0.0-alph… test asynchronous promises generators                                                                  
 aml                   A simple asynchronous module loader with dependency…     =xudafeng      2013-10-09 1.0.0    module loader                                                                              
 ampm                   Data Dependence Async Module System(empty! preserved for…  =jin_preserved    2012-10-06 0.1.0                                                                                        
 amulet                  As-soon-as-possible streaming async mustache templating   =chbrown       2014-01-14 1.0.7    template mustache mu asynchronous streaming nodeps                                                            
 an-async                 Checks if the given API is an async or not.         =hemanth       2014-03-30 0.1.0    async check                                                                               
 analytics.js-loader           Asynchronously load segment.com analytics.js with an npm…  =vvo         2015-01-29 1.0.0    analytics.js segment.com loader browserify                                                                
 and-then                 A minimal CommonJS Promises/A library with a twist.     =aravindet      2013-05-12 0.1.0    async deferred promise future                                                                      
 ...snip...


To install a package simply type:
npm install <package> -g

The -g flag means "global".  The usual purpose for global installation is to install the binary version of a package. Depending on your permissions, installing globally will require access to the /usr/lib folder, which might require you to run this command as root (eg. sudo npm install).


Using Express


The next step is to demonstrate what express is capable of for generating a web application:
 craig@U14BASEBIG01:~$ express --help  
  Usage: express [options] [dir]  
  Options:  
   -h, --help     output usage information  
   -V, --version    output the version number  
   -e, --ejs      add ejs engine support (defaults to jade)  
     --hbs      add handlebars engine support  
   -H, --hogan     add hogan.js engine support  
   -c, --css <engine> add stylesheet <engine> support (less|stylus|compass) (defaults to plain css)  
     --git      add .gitignore  
   -f, --force     force on non-empty directory  


To create a project folder in express, type:
 craig@U14BASEBIG01:~$ express myapp -s  
   create : myapp  
   create : myapp/package.json  
   create : myapp/app.js  
   create : myapp/public  
   create : myapp/public/javascripts  
   create : myapp/public/images  
   create : myapp/routes  
   create : myapp/routes/index.js  
   create : myapp/routes/users.js  
   create : myapp/views  
   create : myapp/views/index.jade  
   create : myapp/views/layout.jade  
   create : myapp/views/error.jade  
   create : myapp/public/stylesheets  
   create : myapp/public/stylesheets/style.css  
   create : myapp/bin  
   create : myapp/bin/www  
   install dependencies:  
    $ cd myapp && npm install  
   run the app:  
    $ DEBUG=myapp:* ./bin/www  

This creates a scaffold application for us:
 craig@U14BASEBIG01:~/myapp$ tree  
 .  
 ├── app.js  
 ├── bin  
 │   └── www  
 ├── package.json  
 ├── public  
 │   ├── images  
 │   ├── javascripts  
 │   └── stylesheets  
 │     └── style.css  
 ├── routes  
 │   ├── index.js  
 │   └── users.js  
 └── views  
   ├── error.jade  
   ├── index.jade  
   └── layout.jade  
 7 directories, 9 files  



Understanding the Express Web Application


Three primary folders were created in the root of the project:

  • public
    • This folder contains all the static assets (images, javascript files, HTML) with a sub-folder for each
  • routes
    • ?
  • views
    • This folder is used when we want to serve up a view to the browser.
    • View engines (like Jade) let you process HTML in a more dynamic way so that a display page can be generated to the browser.  


package.json

The package.json file is similar to a POM file in Maven:
 {  
  "name": "my-awesome-test-app",  
  "version": "0.0.1",  
  "private": true,  
  "scripts": {  
   "start": "node ./bin/www"  
  },  
  "dependencies": {  
   "body-parser": "~1.10.2",  
   "cookie-parser": "~1.3.3",  
   "debug": "~2.1.1",  
   "express": "~4.11.1",  
   "jade": "~1.9.1",  
   "morgan": "~1.5.1",  
   "serve-favicon": "~2.2.0"  
  }  
 }  

The node package manager (npm) requires a package.json file.  This will describe your module on npm, if you ever decide to publish it.

Like the Maven POM file, the package.json structure describes the dependencies of the application.


Running the Web Application


Continuing the analogy to Maven for Java EE applications, the command "npm install" will install the web application.

To download the dependencies this module requires, navigate to the generated web app and type "npm install" on the terminal:
 craig@U14BASEBIG01:~/myapp$ npm install  
 debug@2.1.1 node_modules/debug  
 +-- ms@0.6.2  
 cookie-parser@1.3.3 node_modules/cookie-parser  
 +-- cookie@0.1.2  
 +-- cookie-signature@1.0.5  
 morgan@1.5.1 node_modules/morgan  
 +-- basic-auth@1.0.0  
 +-- depd@1.0.0  
 +-- on-finished@2.2.0 (ee-first@1.1.0)  
 serve-favicon@2.2.0 node_modules/serve-favicon  
 +-- ms@0.7.0  
 +-- fresh@0.2.4  
 +-- parseurl@1.3.0  
 +-- etag@1.5.1 (crc@3.2.1)  
 body-parser@1.10.2 node_modules/body-parser  
 +-- bytes@1.0.0  
 +-- media-typer@0.3.0  
 +-- raw-body@1.3.2  
 +-- depd@1.0.0  
 +-- qs@2.3.3  
 +-- on-finished@2.2.0 (ee-first@1.1.0)  
 +-- iconv-lite@0.4.6  
 +-- type-is@1.5.6 (mime-types@2.0.8)  
 express@4.11.1 node_modules/express  
 +-- merge-descriptors@0.0.2  
 +-- utils-merge@1.0.0  
 +-- methods@1.1.1  
 +-- fresh@0.2.4  
 +-- cookie@0.1.2  
 +-- escape-html@1.0.1  
 +-- range-parser@1.0.2  
 +-- cookie-signature@1.0.5  
 +-- finalhandler@0.3.3  
 +-- vary@1.0.0  
 +-- media-typer@0.3.0  
 +-- parseurl@1.3.0  
 +-- serve-static@1.8.1  
 +-- content-disposition@0.5.0  
 +-- path-to-regexp@0.1.3  
 +-- depd@1.0.0  
 +-- on-finished@2.2.0 (ee-first@1.1.0)  
 +-- qs@2.3.3  
 +-- etag@1.5.1 (crc@3.2.1)  
 +-- proxy-addr@1.0.5 (forwarded@0.1.0, ipaddr.js@0.1.6)  
 +-- send@0.11.1 (destroy@1.0.3, ms@0.7.0, mime@1.2.11)  
 +-- type-is@1.5.6 (mime-types@2.0.8)  
 +-- accepts@1.2.2 (negotiator@0.5.0, mime-types@2.0.8)  
 jade@1.9.1 node_modules/jade  
 +-- character-parser@1.2.1  
 +-- void-elements@1.0.0  
 +-- commander@2.6.0  
 +-- mkdirp@0.5.0 (minimist@0.0.8)  
 +-- transformers@2.1.0 (promise@2.0.0, css@1.0.8, uglify-js@2.2.5)  
 +-- constantinople@3.0.1 (acorn-globals@1.0.2)  
 +-- with@4.0.0 (acorn@0.8.0, acorn-globals@1.0.2)  
 +-- coveralls@2.11.2 (lcov-parse@0.0.6, log-driver@1.2.4, js-yaml@3.0.1, request@2.40.0)  

All the dependencies that are mentioned in the package.json file and haven't yet been downloaded to the system, will be downloaded at this time.  Libraries from node_modules are then used in the source code we write.

The generated node_modules folder is large.

Within my web app, 296 directories and 1071 files were created:
 craig@U14BASEBIG01:~/myapp/node_modules$ tree -d
 .  
 +-- body-parser  
 ¦   +-- lib  
 ¦   ¦   +-- types  
 ¦   +-- node_modules  
 ¦     +-- bytes  
 ¦     +-- depd  
 ¦     ¦   +-- lib  
 ¦     ¦     +-- compat  
 ¦     +-- iconv-lite  
 ¦     ¦   +-- encodings  
 ¦     ¦   ¦   +-- tables  
 ¦     ¦   +-- lib  
 ¦     +-- media-typer  
 ¦     +-- on-finished  
 ¦     ¦   +-- node_modules  
 ¦     ¦     +-- ee-first  
 ¦     +-- qs  
 ¦     ¦   +-- lib  
 ¦     ¦   +-- test  
 ¦     +-- raw-body  
 ¦     +-- type-is  
 ¦       +-- node_modules  
 ¦         +-- mime-types  
 ¦           +-- node_modules  
 ¦             +-- mime-db  
 +-- cookie-parser  
 ¦   +-- lib  
 ¦   +-- node_modules  
 ¦     +-- cookie  
 ¦     +-- cookie-signature  
 +-- debug  
 ¦   +-- node_modules  
 ¦     +-- ms  
 +-- express  
 ¦   +-- lib  
 ¦   ¦   +-- middleware  
 ¦   ¦   +-- router  
 ¦   +-- node_modules  
 ¦     +-- accepts  
 ¦     ¦   +-- node_modules  
 ¦     ¦     +-- mime-types  
 ¦     ¦     ¦   +-- node_modules  
 ¦     ¦     ¦     +-- mime-db  
 ¦     ¦     +-- negotiator  
 ¦     ¦       +-- lib  
 ¦     +-- content-disposition  
 ¦     +-- cookie  
 ¦     +-- cookie-signature  
 ¦     +-- depd  
 ¦     ¦   +-- lib  
 ¦     ¦     +-- compat  
 ¦     +-- escape-html  
 ¦     +-- etag  
 ¦     ¦   +-- node_modules  
 ¦     ¦     +-- crc  
 ¦     ¦       +-- lib  
 ¦     +-- finalhandler  
 ¦     +-- fresh  
 ¦     +-- media-typer  
 ¦     +-- merge-descriptors  
 ¦     +-- methods  
 ¦     +-- on-finished  
 ¦     ¦   +-- node_modules  
 ¦     ¦     +-- ee-first  
 ¦     +-- parseurl  
 ¦     +-- path-to-regexp  
 ¦     +-- proxy-addr  
 ¦     ¦   +-- node_modules  
 ¦     ¦     +-- forwarded  
 ¦     ¦     +-- ipaddr.js  
 ¦     ¦       +-- lib  
 ¦     ¦       +-- src  
 ¦     ¦       +-- test  
 ¦     +-- qs  
 ¦     ¦   +-- lib  
 ¦     ¦   +-- test  
 ¦     +-- range-parser  
 ¦     +-- send  
 ¦     ¦   +-- node_modules  
 ¦     ¦     +-- destroy  
 ¦     ¦     +-- mime  
 ¦     ¦     ¦   +-- types  
 ¦     ¦     +-- ms  
 ¦     +-- serve-static  
 ¦     +-- type-is  
 ¦     ¦   +-- node_modules  
 ¦     ¦     +-- mime-types  
 ¦     ¦       +-- node_modules  
 ¦     ¦         +-- mime-db  
 ¦     +-- utils-merge  
 ¦     +-- vary  
 +-- jade  
 ¦   +-- bin  
 ¦   +-- lib  
 ¦   ¦   +-- nodes  
 ¦   +-- node_modules  
 ¦     +-- character-parser  
 ¦     +-- commander  
 ¦     +-- constantinople  
 ¦     ¦   +-- node_modules  
 ¦     ¦   ¦   +-- acorn-globals  
 ¦     ¦   ¦     +-- node_modules  
 ¦     ¦   ¦       +-- acorn  
 ¦     ¦   ¦         +-- bin  
 ¦     ¦   ¦         +-- test  
 ¦     ¦   ¦         ¦   +-- compare  
 ¦     ¦   ¦         +-- tools  
 ¦     ¦   ¦         +-- util  
 ¦     ¦   +-- test  
 ¦     +-- coveralls  
 ¦     ¦   +-- bin  
 ¦     ¦   +-- fixtures  
 ¦     ¦   ¦   +-- lib  
 ¦     ¦   +-- lib  
 ¦     ¦   +-- node_modules  
 ¦     ¦   ¦   +-- js-yaml  
 ¦     ¦   ¦   ¦   +-- bin  
 ¦     ¦   ¦   ¦   +-- examples  
 ¦     ¦   ¦   ¦   +-- lib  
 ¦     ¦   ¦   ¦   ¦   +-- js-yaml  
 ¦     ¦   ¦   ¦   ¦     +-- schema  
 ¦     ¦   ¦   ¦   ¦     +-- type  
 ¦     ¦   ¦   ¦   ¦       +-- js  
 ¦     ¦   ¦   ¦   +-- node_modules  
 ¦     ¦   ¦   ¦     +-- argparse  
 ¦     ¦   ¦   ¦     ¦   +-- examples  
 ¦     ¦   ¦   ¦     ¦   +-- lib  
 ¦     ¦   ¦   ¦     ¦   ¦   +-- action  
 ¦     ¦   ¦   ¦     ¦   ¦   ¦   +-- append  
 ¦     ¦   ¦   ¦     ¦   ¦   ¦   +-- store  
 ¦     ¦   ¦   ¦     ¦   ¦   +-- argument  
 ¦     ¦   ¦   ¦     ¦   ¦   +-- help  
 ¦     ¦   ¦   ¦     ¦   +-- node_modules  
 ¦     ¦   ¦   ¦     ¦     +-- underscore  
 ¦     ¦   ¦   ¦     ¦     +-- underscore.string  
 ¦     ¦   ¦   ¦     ¦       +-- lib  
 ¦     ¦   ¦   ¦     +-- esprima  
 ¦     ¦   ¦   ¦       +-- bin  
 ¦     ¦   ¦   ¦       +-- test  
 ¦     ¦   ¦   +-- lcov-parse  
 ¦     ¦   ¦   ¦   +-- lib  
 ¦     ¦   ¦   ¦   +-- tests  
 ¦     ¦   ¦   ¦     +-- info  
 ¦     ¦   ¦   +-- log-driver  
 ¦     ¦   ¦   ¦   +-- coverage  
 ¦     ¦   ¦   ¦     +-- lcov-report  
 ¦     ¦   ¦   ¦       +-- logdriver  
 ¦     ¦   ¦   +-- request  
 ¦     ¦   ¦     +-- lib  
 ¦     ¦   ¦     +-- node_modules  
 ¦     ¦   ¦       +-- aws-sign2  
 ¦     ¦   ¦       +-- forever-agent  
 ¦     ¦   ¦       +-- form-data  
 ¦     ¦   ¦       ¦   +-- lib  
 ¦     ¦   ¦       ¦   +-- node_modules  
 ¦     ¦   ¦       ¦     +-- async  
 ¦     ¦   ¦       ¦     ¦   +-- lib  
 ¦     ¦   ¦       ¦     +-- combined-stream  
 ¦     ¦   ¦       ¦     ¦   +-- lib  
 ¦     ¦   ¦       ¦     ¦   +-- node_modules  
 ¦     ¦   ¦       ¦     ¦     +-- delayed-stream  
 ¦     ¦   ¦       ¦     ¦       +-- lib  
 ¦     ¦   ¦       ¦     ¦       +-- test  
 ¦     ¦   ¦       ¦     ¦         +-- integration  
 ¦     ¦   ¦       ¦     +-- mime  
 ¦     ¦   ¦       ¦       +-- types  
 ¦     ¦   ¦       +-- hawk  
 ¦     ¦   ¦       ¦   +-- example  
 ¦     ¦   ¦       ¦   +-- images  
 ¦     ¦   ¦       ¦   +-- lib  
 ¦     ¦   ¦       ¦   +-- node_modules  
 ¦     ¦   ¦       ¦   ¦   +-- boom  
 ¦     ¦   ¦       ¦   ¦   ¦   +-- images  
 ¦     ¦   ¦       ¦   ¦   ¦   +-- lib  
 ¦     ¦   ¦       ¦   ¦   ¦   +-- test  
 ¦     ¦   ¦       ¦   ¦   +-- cryptiles  
 ¦     ¦   ¦       ¦   ¦   ¦   +-- lib  
 ¦     ¦   ¦       ¦   ¦   ¦   +-- test  
 ¦     ¦   ¦       ¦   ¦   +-- hoek  
 ¦     ¦   ¦       ¦   ¦   ¦   +-- images  
 ¦     ¦   ¦       ¦   ¦   ¦   +-- lib  
 ¦     ¦   ¦       ¦   ¦   ¦   +-- test  
 ¦     ¦   ¦       ¦   ¦   ¦     +-- modules  
 ¦     ¦   ¦       ¦   ¦   +-- sntp  
 ¦     ¦   ¦       ¦   ¦     +-- examples  
 ¦     ¦   ¦       ¦   ¦     +-- lib  
 ¦     ¦   ¦       ¦   ¦     +-- test  
 ¦     ¦   ¦       ¦   +-- test  
 ¦     ¦   ¦       +-- http-signature  
 ¦     ¦   ¦       ¦   +-- lib  
 ¦     ¦   ¦       ¦   +-- node_modules  
 ¦     ¦   ¦       ¦     +-- asn1  
 ¦     ¦   ¦       ¦     ¦   +-- lib  
 ¦     ¦   ¦       ¦     ¦   ¦   +-- ber  
 ¦     ¦   ¦       ¦     ¦   +-- tst  
 ¦     ¦   ¦       ¦     ¦     +-- ber  
 ¦     ¦   ¦       ¦     +-- assert-plus  
 ¦     ¦   ¦       ¦     +-- ctype  
 ¦     ¦   ¦       ¦       +-- man  
 ¦     ¦   ¦       ¦       ¦   +-- man3ctype  
 ¦     ¦   ¦       ¦       +-- tools  
 ¦     ¦   ¦       +-- json-stringify-safe  
 ¦     ¦   ¦       +-- mime-types  
 ¦     ¦   ¦       ¦   +-- lib  
 ¦     ¦   ¦       +-- node-uuid  
 ¦     ¦   ¦       ¦   +-- benchmark  
 ¦     ¦   ¦       ¦   +-- bin  
 ¦     ¦   ¦       ¦   +-- test  
 ¦     ¦   ¦       +-- oauth-sign  
 ¦     ¦   ¦       +-- qs  
 ¦     ¦   ¦       ¦   +-- lib  
 ¦     ¦   ¦       ¦   +-- test  
 ¦     ¦   ¦       +-- stringstream  
 ¦     ¦   ¦       +-- tough-cookie  
 ¦     ¦   ¦       ¦   +-- lib  
 ¦     ¦   ¦       ¦   +-- node_modules  
 ¦     ¦   ¦       ¦     +-- punycode  
 ¦     ¦   ¦       +-- tunnel-agent  
 ¦     ¦   +-- test  
 ¦     +-- mkdirp  
 ¦     ¦   +-- bin  
 ¦     ¦   +-- examples  
 ¦     ¦   +-- node_modules  
 ¦     ¦   ¦   +-- minimist  
 ¦     ¦   ¦     +-- example  
 ¦     ¦   ¦     +-- test  
 ¦     ¦   +-- test  
 ¦     +-- transformers  
 ¦     ¦   +-- lib  
 ¦     ¦   +-- node_modules  
 ¦     ¦     +-- css  
 ¦     ¦     ¦   +-- node_modules  
 ¦     ¦     ¦     +-- css-parse  
 ¦     ¦     ¦     +-- css-stringify  
 ¦     ¦     +-- promise  
 ¦     ¦     ¦   +-- node_modules  
 ¦     ¦     ¦     +-- is-promise  
 ¦     ¦     +-- uglify-js  
 ¦     ¦       +-- bin  
 ¦     ¦       +-- lib  
 ¦     ¦       +-- node_modules  
 ¦     ¦       ¦   +-- optimist  
 ¦     ¦       ¦   ¦   +-- example  
 ¦     ¦       ¦   ¦   +-- node_modules  
 ¦     ¦       ¦   ¦   ¦   +-- wordwrap  
 ¦     ¦       ¦   ¦   ¦     +-- example  
 ¦     ¦       ¦   ¦   ¦     +-- test  
 ¦     ¦       ¦   ¦   +-- test  
 ¦     ¦       ¦   ¦     +-- _  
 ¦     ¦       ¦   +-- source-map  
 ¦     ¦       ¦     +-- build  
 ¦     ¦       ¦     +-- lib  
 ¦     ¦       ¦     ¦   +-- source-map  
 ¦     ¦       ¦     +-- node_modules  
 ¦     ¦       ¦     ¦   +-- amdefine  
 ¦     ¦       ¦     +-- test  
 ¦     ¦       ¦       +-- source-map  
 ¦     ¦       +-- test  
 ¦     ¦       ¦   +-- compress  
 ¦     ¦       +-- tools  
 ¦     +-- void-elements  
 ¦     ¦   +-- test  
 ¦     +-- with  
 ¦       +-- node_modules  
 ¦         +-- acorn  
 ¦         ¦   +-- bin  
 ¦         ¦   +-- test  
 ¦         ¦   ¦   +-- compare  
 ¦         ¦   +-- tools  
 ¦         ¦   +-- util  
 ¦         +-- acorn-globals  
 ¦           +-- node_modules  
 ¦             +-- acorn  
 ¦               +-- bin  
 ¦               +-- test  
 ¦               ¦   +-- compare  
 ¦               +-- tools  
 ¦               +-- util  
 +-- morgan  
 ¦   +-- node_modules  
 ¦     +-- basic-auth  
 ¦     +-- depd  
 ¦     ¦   +-- lib  
 ¦     ¦     +-- compat  
 ¦     +-- on-finished  
 ¦       +-- node_modules  
 ¦         +-- ee-first  
 +-- serve-favicon  
   +-- node_modules  
     +-- etag  
     ¦   +-- node_modules  
     ¦     +-- crc  
     ¦       +-- lib  
     +-- fresh  
     +-- ms  
     +-- parseurl  
 296 directories  

To start the web application, type "node start app.js" from within the generated web app on the terminal session:
 craig@U14BASEBIG01:~/myapp$ npm start app.js   
 > myapp@0.0.0 start /home/craig/myapp  
 > node ./bin/www app.js  
 GET / 200 216.324 ms - 170  
 GET /stylesheets/style.css 200 8.295 ms - 110  
 GET /favicon.ico 404 23.411 ms - 1026  
 GET /favicon.ico 404 12.071 ms - 1026  

I start up my web browser, and go to my localhost at port 3000:



References

  1. [StackOverflow] Installing Express on Ubuntu
    1. The answer from olivieryem was a real help.  
    2. I kept trying "sudo npm install express -g" and that didn't work.  
    3. This comment from Alex Ford (video link below) explains the issue:
  2. [YouTube] Node.js and Express 101
    1. Great introductory advice for node.js 

2 comments:

  1. I feel happy and learn more about this subject. keep sharing your information regularly for my future reference. TThanks for sharing an article like this.
    Node JS Online training
    Node JS training in Hyderabad

    ReplyDelete
  2. Excellent blog, informative and knowledgeable content. Thanks for sharing this blog with us.
    Mern Stack Training in Hyderabad
    Mern Stack Online Training in Hyderabad

    ReplyDelete