Catbook Workshop: Intro to NodeJS. Monde Duinkharjav

Similar documents
MongoDB. Robert M. Vunabandi

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

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

Human-Computer Interaction Design

Salvatore Rinzivillo VISUAL ANALYTICS

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

Catbook Workshop 1: Client Side JS. Danny Tang

Getting started with Tabris.js Tutorial Ebook

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

We are assuming you have node installed!

Backend Development. SWE 432, Fall Web Application Development

Brunch Documentation. Release Brunch team

CS193X: Web Programming Fundamentals

Lab 1 - Introduction to Angular

Web Application Development

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

welcome to BOILERCAMP HOW TO WEB DEV

Chapter 1 - Development Setup of Angular

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

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

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

webpack bundle inner structure and optimization Alexey Ivanov, Evil Martians

Running and Debugging Custom Components Locally

MEAN February. techdt.la

Defining New Node-RED Nodes

Quick Desktop Application Development Using Electron

JavaScript on the Command Line & PRATIK PATEL CTO TripLingo Labs

IN4MATX 133: User Interface Software

Full Stack Web Framework with BBG

Persistence & State. SWE 432, Fall 2016 Design and Implementation of Software for the Web

Getting Started With NodeJS Feature Flags

Angular 2 Programming

Client Side JavaScript and AJAX

IBM Image-Analysis Node.js

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

git commit --amend git rebase <base> git reflog git checkout -b Create and check out a new branch named <branch>. Drop the -b

HTML & CSS. Rupayan Neogy

Full Stack boot camp

npm install [<name> [<name>...]] [--save --save-dev --save-optional]

MOdern Java(Script) Server Stack

Guides SDL Server Documentation Document current as of 04/06/ :35 PM.

Lab 6: Testing. Software Studio DataLab, CS, NTHU

Microservices with Node.js

RequireJS Javascript Modules for the Browser. By Ben Keith Quoin, Inc.

delegator Documentation

withenv Documentation

Software Engineering

Data Types and the main Function

DBNsim. Giorgio Giuffrè. 0 Abstract How to run it on your machine How to contribute... 2

IERG 4210 Tutorial 08

Git. Charles J. Geyer School of Statistics University of Minnesota. Stat 8054 Lecture Notes

Kivy Designer Documentation

Building a Django Twilio Programmable Chat Application

Express.JS. Prof. Cesare Pautasso Modularity

Installing Design Room ONE

Quick.JS Documentation

Django-CSP Documentation

Lets take a closer look at Ajax & node.js. Claudia Hauff TI1506: Web and Database Technology

Bitnami Node.js for Huawei Enterprise Cloud

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

Tizen TCT User Guide

Git Tutorial. André Sailer. ILD Technical Meeting April 24, 2017 CERN-EP-LCD. ILD Technical Meeting, Apr 24, 2017 A. Sailer: Git Tutorial 1/36

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

JavaScript Rd2. -Kyle Simpson, You Don t Know JS

How to configure DBxtra to use Internet Information Services on Windows Server 2012

The Pizza Shop. Overview. Initial Setup

IN4MATX 133: User Interface Software

Installing VS Code. Instructions for the Window OS.

a Very Short Introduction to AngularJS

Lecture 8. ReactJS 1 / 24

Revision control. INF5750/ Lecture 2 (Part I)

roots Documentation Release jeff escalante

TangeloHub Documentation

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

DrupalCon Barcelona Preston So September 22, 2015

django-baton Documentation

Unifer Documentation. Release V1.0. Matthew S

pyldavis Documentation

Web Development for Dinosaurs An Introduction to Modern Web Development

Quick housekeeping Last Two Homeworks Extra Credit for demoing project prototypes Reminder about Project Deadlines/specifics Class on April 12th Resul

git Version: 2.0b Merge combines trees, and checks out the result Pull does a fetch, then a merge If you only can remember one command:

Guides SDL Server Documentation Document current as of 05/24/ :13 PM.

gettext.js Documentation

NODE.JS MOCK TEST NODE.JS MOCK TEST I

Getting Started with ReactJS

Guides SDL Server Documentation Document current as of 03/08/ :14 PM.

CS 520: VCS and Git. Intermediate Topics Ben Kushigian

Cookies, sessions and authentication

Bitdock. Release 0.1.0

Guide for Building Web Application Using PHP and Mysql

JSON Evaluation. User Store

JavaScript: Introduction, Types

IBM Watson Solutions Business and Academic Partners

nacelle Documentation

Introduction to Git and GitHub for Writers Workbook February 23, 2019 Peter Gruenbaum

COMP 2406: Fundamentals of Web Applications. Winter 2014 Mid-Term Exam Solutions

SendCloud OpenCart 2 Extension Documentation

Lab session 1 Git & Github

mri Documentation Release Nate Harada

PiranaJS installation guide

Transcription:

Catbook Workshop: Intro to NodeJS Monde Duinkharjav

What is NodeJS?

NodeJS is... A Javascript RUNTIME ENGINE NOT a framework NOT Javascript nor a JS package It is a method for running your code in Javascript. Let s see how In your terminal run the command

$ nodejs > node (for Windows users)

> console.log( Hello World ); Hello World

Pop Quiz: Where else can you find a javascript runtime engine?

Programming Language Libraries Programming languages have many libraries. E.g. numpy, scipy for python. In python, we have pip. This manages your python packages. In javascript, we have...

Node Package Manager (NPM)

Initializing a Javascript Project using NPM $ npm init This command creates package.json. This file keeps track of info about the project

Let s create a web server using the http package Create a file called app.js. And in this file, type: Now, running the command you will get: $ nodejs app.js Hello World

Let s create a web server using the http package $ npm install http --save (parallel to pip install) This command will do two things: 1. Add the http package DEPENDENCY to your package.json 2. Download the http library in under the directory node_modules WARNING: this installs http only for the current project

IMPORTANT TANGENT Make a file called.gitignore in your project s directory And write inside it: node_modules/ Why? You don t want to push thousands of lines of code from libraries into your repository. Instead, you make git ignore the node_modules directory. When you later clone your project code, you always run $ npm install And reinstall node_modules to your machine

Let s import the http package into our project In app.js (equivalent to import numpy for python) This loads the http library into our project. Let s use this package and start a webserver: You can run the app now with: $ nodejs app.js

If you re lost: Go to go.6148.io/workshop2 and clone git checkout step1

function(req, res) {} 1. req stands for request, res stands for response 2. We re passing in a function to these methods: Whenever a request is made, this function is invoked. The argument res is mutated by this function. 3. This type of function pops up a LOT in web server request handling

Let s test our web server out Open your web browser: http://localhost:3000 Okay, we re done! We have a web app. Thank you for coming. You re done

Let s test our web server out Real applications are many orders of magnitude more complex so the code base can get out of hand really quickly. Introducing: Express A Javascript library that provides a web server architecture. Rupayan s Take on Express: Organize my web server. Let s install it... hold up. Let s do some housekeeping first.

Housekeeping 1. Create a directory called src and public 2. Move app.js into src 3. From here on we ll use a wrapper to nodejs: nodemon a. Run $ npm install nodemon --save-dev b. Add npm start script to package.json

What happened to our project? 1. Server logic code is now in src. Static files accessible for all clients in public 2. Nodemon detects when you change the files in your app and restarts your app. 3. Dev Dependencies are the libraries you use for development. Good to have this distinction for development vs actual application logic 4. $ npm start is an ALIAS to typing nodemon src/app.js which is a good abstraction to make.

Using express to send a Hello World message

Exercise: Create a new endpoint Aside: endpoint - a reference to a service a web application provides. E.g. / is the root endpoint. We can have a /u/profile endpoint that can be reached by typing http://<webapp url>/u/profile Exercise: Create a new endpoint called /u/profile that sends the message My Profile. If you re behind, you can run to hop in right before you need to do this exercise git reset --hard git checkout step2

Now let s send our.html files instead of plain text 1. Create a directory called /src/views 2. Change res.send to res.sendfile

Now let s send our.html files instead of plain text Oops when we request the endpoint, the css and js files don t work properly Let s fix that: 1. Add line 6 to your code 2. Move the js and css folders into public 3. Change the references in the html

Exercise: Render the /u/profile endpoint - /u/profile endpoint should render the profile.html page we created on Tuesday s lecture.

Okay moving on more Housekeeping What happens if we try to reach the endpoint /aaronsipsersucks or /dannysrealnameisdanielwinstontang

Okay moving on more Housekeeping What happens if we try to reach the endpoint /aaronsipsersucks or /dannysrealnameisdanielwinstontang 404!!!

Okay moving on more Housekeeping We should also take care of 500 Internal Errors. Not really important how this works exactly tbh i don t exactly know how this works myself.

Working with several files As projects get larger, one app.js file will be too much to deal with. Let s demonstrate how this is done by moving our view endpoints somewhere else. 1. Create a directory called src/routes 2. Inside, make a file called views.js

module.exports = router Remember? const http = require( http ); This is importing http. Then, you export a package by typing: module.exports = ; We exported router just now, we import it back in our app.js by typing:

Final results: go.6148.io/workshop3