Introduction to Express.js. CSC309 Feb. 6, 2015 Surya Nallu

Similar documents
Catbook Workshop: Intro to NodeJS. Monde Duinkharjav

Node.js. Node.js Overview. CS144: Web Applications

Backend Development. SWE 432, Fall Web Application Development

Practical Node.js. Building Real-World Scalable Web Apps. Apress* Azat Mardan

NODE.JS MOCK TEST NODE.JS MOCK TEST I

Bitnami MEAN for Huawei Enterprise Cloud

Microservices with Node.js

TangeloHub Documentation

PiranaJS installation guide

5th April Installation Manual. Department of Computing and Networking Software Development Degree

Full Stack Web Framework with BBG

Getting Started With NodeJS Feature Flags

COMP 2406: Fundamentals of Web Applications. Fall 2013 Mid-Term Exam Solutions

There are two main workflows for working with Cordova projects, Web focused and Platform focused.

MongoDB. Robert M. Vunabandi

Hands-on Lab Session 9011 Working with Node.js Apps in IBM Bluemix. Pam Geiger, Bluemix Enablement

We are assuming you have node installed!

Bitnami Node.js for Huawei Enterprise Cloud

Getting started with Tabris.js Tutorial Ebook

Automate with Grunt. Extracted from: The Build Tool for JavaScript. The Pragmatic Bookshelf

Full Stack boot camp

LECTURE 15. Web Servers

Running and Debugging Custom Components Locally

Plumeria Documentation

Topic 16: Validation. CITS3403 Agile Web Development. Express, Angular and Node, Chapter 11

Backend Development. SWE 432, Fall 2017 Design and Implementation of Software for the Web

What is Node.js? Tim Davis Director, The Turtle Partnership Ltd

Tools. SWE 432, Fall Design and Implementation of Software for the Web

Plone Performance Testing Documentation

delegator Documentation

web.py Tutorial Tom Kelliher, CS 317 This tutorial is the tutorial from the web.py web site, with a few revisions for our local environment.

Python Programming Exercises 1

MEAN February. techdt.la

Installing PHP on Windows 10 Bash and Starting a Local Server

Indium Documentation. Release Nicolas Petton

This tutorial is meant for software developers who want to learn how to lose less time on API integrations!

Having Fun with Social Coding. Sean Handley. February 25, 2010

Python web frameworks

Getting Started with IBM Bluemix Hands-On Workshop. Module 6a: Services

Exercises. Cacti Installation and Configuration

Exercises. Cacti Installation and Configuration

Web Application Development

Exercise 1. Bluemix and the Cloud Foundry command-line interface (CLI)

bst Documentation Release John Kelvie, Bela Vizy, Michael Myers

Module - P7 Lecture - 15 Practical: Interacting with a DBMS

Privacy and Security in Online Social Networks Department of Computer Science and Engineering Indian Institute of Technology, Madras

Web API Lab folder 07_webApi : webapi.jsp your testapijs.html testapijq.html that works functionally the same as the page testapidomjs.

3rd Party Application Deployment Instructions

Unifer Documentation. Release V1.0. Matthew S

Tuesday, January 13, Backend III: Node.js with Databases

Download, Install and Setup the Linux Development Workload Create a New Linux Project Configure a Linux Project Configure a Linux CMake Project

Quick Desktop Application Development Using Electron

Human-Computer Interaction Design

IBM Image-Analysis Node.js

JavaScript on the Command Line & PRATIK PATEL CTO TripLingo Labs

ewd-feder8 Installation & Reference Guide

Bitnami HHVM for Huawei Enterprise Cloud

A practical introduction

Developing Solutions for Google Cloud Platform (CPD200) Course Agenda

IEMS 5722 Mobile Network Programming and Distributed Server Architecture Semester 2

Creating a Multi-Container Pod

FoxInCloud. A-Z tutorial, Session 3. Requires FAA & FAS V2.0+

Installing Design Room ONE

Topics Augmenting Application.cfm with Filters. What a filter can do. What s a filter? What s it got to do with. Isn t it a java thing?

Brunch Documentation. Release Brunch team

Intro to Linux & Command Line

How to Secure SSH with Google Two-Factor Authentication

Homework #7 Google Cloud Platform

A Hands on Introduction to Docker

Step 1: Setup a Gitlab account

AWS Lambda. 1.1 What is AWS Lambda?

Alex Young Marc Harter

Introduction to VMs & Containers

Bambu API Documentation

OnRISC. IoT Manual. Vision Systems GmbH. Edition: October 2017

a Very Short Introduction to AngularJS

Wanchain Hackathon Handbook San Jose

Libra Client Documentation

We want to install putty, an ssh client on the laptops. In the web browser goto:

Kollaborate Server. Installation Guide

Bitnami JRuby for Huawei Enterprise Cloud

Carbon Black QRadar App User Guide

CSCI 201 Lab 1 Environment Setup

INF5750. Introduction to JavaScript and Node.js

Make Your Own Linux Module CS 444/544

crane Documentation Release Globo.com

Node.js 8 the Right Way

Index. Backbone.js app, 274 Behavior-driven development (BDD) language, 252 bodyparser() method, 257

Fundamentals: Expressions and Assignment

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

bistro Documentation Release dev Philippe Veber

Chapter 1 - Development Setup of Angular

Sparkfun Lunch & Learn. Jeff Boody

welcome to BOILERCAMP HOW TO WEB DEV

datapusher Documentation

About the Tutorial. Audience. Prerequisites. Disclaimer & Copyright. TurboGears

Node.js the Right Way

Parse. Jamie Karraker 12 MEng 13

Technical Manual. Software Quality Analysis as a Service (SQUAAD) Team No.1. Implementers: Aleksandr Chernousov Chris Harman Supicha Phadungslip

WorldSpace Attest Quick Start Guide

Transcription:

Introduction to Express.js CSC309 Feb. 6, 2015 Surya Nallu

What is Express.js? Web application framework for Node.js Light-weight and minimalist Provides boilerplate structure & organization for your web-apps

Installing Express.js Install node and node package manager (npm) sudo apt-get install nodejs on Debian/Ubuntu. Installer available for Mac [1] Installing node should also install npm Running node on a shell would now open an interactive node session (just like python) [1] http://nodejs.org/download/

Installing Express.js We can now create a project (say a blog), initialize it as a node package & install express.js mkdir blog && cd blog npm init Creates a node package (touching package.json) pacakge.json: lists all dependencies (node modules) npm install express --save Install express and add it as a dependency to our app

Hello World - Example Let s write a simple hello world program using node and express. We create a file app.js inside the blog directory, with the following contents: The app is invoked with node app.js on the console. At this point, node listens on port 3000, but doesn t really do much. We can check this out, by accessing http://localhost:3000 on the browser.

Example - Continued With a few more lines: Declare an instance of express called app Accept requests on / (the root path on the URL localhost:3000) and pass it to function (more on this later). The processing function or callback receives the request and is expected to present with a response.

Example - Continued With a few more lines: Send a string as the response.

Example - Continued We can obviously add some dynamically generated content:

Routing Apps needs to know what exactly to do when a request is made to a particular endpoint. http://localhost:3000/ -- / is the endpoint http://localhost:3000/admin -- /admin is the endpoint We do this by defining routes. In the previous example, we defined one route / which returned a string as the response.

Routing - structure app.method(endpoint, HANDLER) Equivalent to app.action(where, what-to-do) METHOD: What kind of request is the route for? Most common ones are GET / POST but express supports a bunch 2 Another generic method called all (covered next week). [2]: http://expressjs.com/guide/routing.html#route-methods

Routing - structure app.method(endpoint, HANDLER) Equivalent to app.action(where, what-to-do) ENDPOINT: What path is the request directed to. This can be a regular expression. app.get('/ab*cd',..); will match: localhost:3000/abcd, localhost:3000/abxyzcd and so on.

Routing - structure app.method(endpoint, HANDLER) Equivalent to app.action(where, what-to-do) ENDPOINT: What path is the request directed to. This can be a regular expression. app.get(/.*cat$/,..); will match: localhost:3000/happycat, localhost:3000/sadcat and so on.

Routing - structure app.method(endpoint, HANDLER) Equivalent to app.action(where, what-to-do) HANDLER: Or a callback function that determines how to process the request. Takes in a few parameters (request and response as an example).

Routing - structure Handler: Sent in an anonymous function that would receive the request and return a response. Data pertaining to this instance of the request can be obtained through the request variable. Data pertaining to the response should be handled through the response variable.

Routing - structure Handler: Handler functions can also be passed as variables for brevity.

Routing chaining handlers Handlers can be chained together. Route handlers take a third parameter called next. Invoking this variable as a function, delegates the request to the next handler (if there is one).

Routing chaining handlers Ordering of the handlers matter. If secret_check() sent in a response (instead of calling next) the delegation to error() won t happen and the handler chain would stop with secret_check()

Response methods

Aside: Logging console.log( ) is extremely useful for logging information server side (by default would print out to the console). Helps with debugging. Prints out the client s IP address for every request they make -- to the console (where you invoked node app.js )

Express generator Express provides a tool that can create and initialize an application skeleton. Sets up a directory structure for isolating your business and presentation logic (among others). Not a norm in any way, can be used as a starting point.

Express generator How to use it? Installing using npm install express-generator g Can then be invoked with express Create an app (for instance, a blog) express blog will generate the directories/files cd blog && npm install will install the dependencies Invoke the server using DEBUG=blog./bin/www

Express generator Provides & sets up some boilerplate code for getting started faster Adds some commonly used dependencies Pretty good starting point for digging deeper into Node.js/Express.js Creates a structure that allows separation of concerns on business/presentation logic (more on this next week)

Resources http://expressjs.com (Sections: Guide, API ref.) http://expressjs.com/starter/faq.html http://code.tutsplus.com/tutorials/introduction-to-express-- net-33367 Some resources on the slides are based on Getting Started section from http://expressjs.com