Node.js

Node.js

Node.js - Wikipedia


Things you can do with Node:
  • read & write
  • connect to databases
  • act as a server for content 
 
-Javascript was originally made for browser to interact with DOM. 
-Node allows run JavaScript on backend. 
-Check your node version on terminal with: node -v
-Type node to run node directly in the terminal. 

Streams:
  • allows you to use data before it is fully loaded.
  • package being sent via stream is called buffer. 

Client and Servers: 
  • IP Address
    • series of numbers.
    • IPv4 vs IPv6
  • Localhost 
    • get loop back ip address which is 127.0.0.1
    • browser is connected to local host, which is own computer.
  • Port#
    • Channel
    • Think of a door to your computer and what traffic you want to let to your computer.
Requests and Responses:
  • Status codes:
    • 200 Ok
    • 404 not found
    • 201
    • 500 internal server error
    • 301 resource moved


Redirection:
  • When I changed my url and now it directs to 404
  • Other websites might have my link still directing there. 
For smaller website you can have personal and small routing system, when website grows larger then you can use helper frameworks as Express. 

Nodemon - is a live server developing tool that triggers browser to change live.


Package management: 
  • git init to initialize json files. 
  • Install packages locally
  • Usually don't upload modules folder to github to share the code. 
  • When we have packages json file with listed dependencies, simply type in project terminal:  
    • npm install

Express: 

Express - helps you with routing management. 

How to output dynamic data: Express can use view engines to do so. 


Partials: - to be used as templates. 



Middleware - any code that runs between request and response time. (any functions)
Order of functions:
  1. app.use(func)
  2. app.get('/', func)
Middleware Examples;
  • Logger middleware to log details of every request
  • Authentication check middlware for protected routes
  • Middleware to parse JSON data from requests
  • Return 404 pages
  • 3rd party middleware: morgan, helmet.
    • let's practice using morgan. 
    • npm install morgan

Mongo with Node.js
  • Mongoose - is an ODM library. Object Document Mapping library
  • Schema - is an architecture of the database

NoSQL:
  • collections
  • documents
SQL:
  • Tables
  • Rows



MVC - 
  • Model
    • Database architecture, 
  • View
    • HTML, CSS, Web Frameworks
  • Control
    • Functionality, Requests
      • Get - retrieve
      • Put - change
      • Post - send








Comments