Giter Club home page Giter Club logo

edx-nodejs's Introduction

Edx -- NodeJS

LinuxFoundationX LFW111x - Introduction to Node.js

Link

Install NodeJS use NVM

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

1. Quick File Server with Serve dependency

/1-mock-static-server
  /static
    /app.js
    /index.html

Install Serve dependency globally

npm install -g serve

Run

cd 1-mock-static-server/
serve -p 5050 static

2. Quick File Server Zero-Dependency

/2-mock-zero-dependency
  /server.js
  /static
    /app.js
    /index.html

Run

cd 2-mock-zero-dependency/
node server.js

The frontend application starting with serve

cd 2-mock-zero-dependency/
serve -p 5050 static

3. Quick File Server with Fastify

Fastify

/3-mock-fastify
  /mock-srv
    (scaffolding create with `npm init fastify`)
  /static
    /app.js
    /index.html

Install Fastify dependency

cd 3-mock-fastify/mock-srv
npm install

Run

cd 3-mock-fastify/mock-srv
npm start

The frontend application starting with serve

cd 3-mock-fastify/
serve -p 5050 static

4. Realtime

the key concept is Web Socket

/4-realtime
  /mock-srv
    (scaffolding create with `npm init fastify`)
  /static
    /app.js
    /index.html

Install Fastify dependency

cd 4-realtime/mock-srv
npm install

Run

cd 4-realtime/mock-srv
npm start

The frontend application starting with serve

cd 4-realtime/
serve -p 5050 static

4.1 Bidirectional Communication

testing from terminal

node -e "http.request('http://localhost:3000/orders/A1', { method: 'POST', headers: {'content-type': 'application/json'}}, (res) => res.pipe(process.stdout)).end(JSON.stringify({amount: 10}))"

the frontend application retrieve the updated data for the order A1

5. Command Line Tool

Create a CLI tool to send request to the server and update the order

/5-cli-tool
  /mock-srv
    (scaffolding create with `npm init fastify`)
  /static
    /app.js
    /index.html

Installing the CLI

cd 5-cli
npm link

Usage

To use the CLI you need started the server and the frontend application as described in the previous sections. Next you can try the cli to automate the update of the order.

5-cli <id> <amount>

# Example
5-cli A1 10

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.