Blockchain Nanodegree Notes 20181111
Lesson 2 Web Services with Node.js
Introduction
RESTful Frameworks: gives you access to guidelines and tools that help you develop applications more efficiently.
REST (Representational State Transfer): Set of rules that defines guidelines based on the HTTP protocol.
Framework: Set of tools and guidelines designed to support the development of web applications.
Why use a framework
- Build rapidly
- Access code that’s been built and tested
- Help extend functionality
13 Node.js frameworks
Framework Homepages
Express.js
Tools we’ll use
- Your Local Desktop
- A Terminal Window
- Code Editor (I’m using VS Code)
- Another Browser window (to view your application)
Preparation
npm init
touch index.js
npm install express --save
Express.js: Get Started
Express.js Hello World Code
const express = require('express')
const app = express()
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(3000, () => console.log('Example app listening on port 3000!'))
node index.js
open localhost:3000
in the browser
Express.js Conclusion
List of books and blogs on their site here.
Each of the modules along with their documentation are listed here.
Practice Express.js
Step 1 | Clone the project repository in this Github repository |
---|---|
Step 2 | Open the terminal and install the packages: npm install |
Step 3 | Open the file app.js and blockcontroller.js and start coding - See additional info below |
Step 4 | Run your application node app.js |
Step 5 | Use Curl or Postman to test the endpoints |
Additional Info for Step 3
Review the boilerplate code
After you’ve cloned your repository and installed the node packages using npm install
, you will need to install the following packages:
- “body-parser”: “^1.18.3”,
- “crypto-js”: “^3.1.9-1”,
- “express”: “^4.16.3”
The package body-parser allows you to parse incoming request bodies in a middleware before your handlers, available under the req.body property
. For more documentation visit this link.
The package crypto-js
you are being using it a lot during this course so far however if you need extra support feel free to read about it in the following link.
The package express
is the most important package because it allows you to use the Express Framework features to create your RESTful API. Check the documentation so you’ll be familiarized with the core concepts of this framework in this link.