CS6320:  SW Engineering of Web Based Systems

 

 

Express: a simple Node.js Framework

minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications. Provides EASIER WAY (than just nodeJS):

  • it adds a DIRECTORY STRUCTURE

it is a minimalist

  • basic routing(mapping URLs -> code/static page), middleware, template engine and static files serving, sessions/cookies

  • (fast) I/O performance of Node.js doesn’t get compromised.

  • Not true MVC framework (people will add another package for the presenation layer -- like Angular JS)

  • because so light weight, as project grows and more devleopers may get codebase that does not apply same design priniciples -- is not a pattern oriented framework:<

     

 

front end setup

uses generator to setup project that defines folder/locations for content

npm install express-generator -g express helloapp

create : helloapp

create : helloapp/package.json

create : helloapp/app.js

create : helloapp/public

create : helloapp/public/images

create : helloapp/routes

create : helloapp/routes/index.js

create : helloapp/routes/users.js

create : helloapp/public/stylesheets

create : helloapp/public/stylesheets/style.css

create : helloapp/views create : helloapp/views/index.jade

create : helloapp/views/layout.jade

create : helloapp/views/error.jade

create : helloapp/bin

create : helloapp/bin/www

 

install dependencies:
$ cd helloapp && npm install

run the app:
$ DEBUG=helloapp:* npm start

create : helloapp/public/javascripts

 

 

middleware -- functions that have access to request/response objects

An Express application is essentially Node.js with a host of middleware functions, 

CODE SAMPLE

 

var app = express(); app.use(cookieParser()); app.use(bodyParser()); app.use(logger()); app.use(authentication());


app.get('/', function (req, res)
{
// ...
});

app.listen(3000);

template engine

 

  • templates let you embed backend variables into an HTML file and when requested it renders the HTML file with the variables set to their actual values

  • uses Pug (template engine)

 

Routing, _ Static Files , _ Middleware, _ Form Processing, Authentication (simple using session)

 

MORE yet read on your own- Cookies, Sessions

 

 
© Lynne Grewe