Coder Social home page Coder Social logo

learning-and-mastering-node.js's Introduction

Learning and Mastering Node.js

A Repository for Those Who Want to Master Node.js and related Frameworks

What is Node.js?

  • It is a JavaScript runtime. It is not a language it is not a framework. The language is JavaScript.
  • Built on the V8 JavaScript engine.
  • Written in C++ language.
  • Essentially allows you to run JavaScript code on the server.

Why is it a good choice for server side technology?

  • It is extremely fast, highly efficient, and highly scalable.
  • It is event driven, non-blocking I/O model.
    • Non-Blocking I/O model
      • Works on a single thread using non-blocking I/O calls.
      • Supports tens of thousands of concurrent connections.
      • Optimizes throughput & scalability in apps with many I/O operations.
      • All of the above makes Node.js apps fast & efficient.
  • Same language on the front and back end.

HTTP Intro - Headers, Body, Status Codes

What is HTTP?

  • Hyper Text Transfer Protocol
  • Communication between web servers & clients
  • HTTP Requests / Responses
  • Includes header & body

Core Node Module

const http = require('http');

cost data = [
  {id: 1, name: 'A'},
  {id: 2, name: 'B'},
  {id: 3, name: 'C'}
];

const server = http.createServer((req, res) => {
  const { headers, url, method } = req;
  console.log(headers, url, method);
  
  res.setHeader('Content-Type', 'application/json');
  res.setHeader('X-Powered-By', 'Node.js');
  res.end(JSON.stringify({
    success: true,
    data: data
  }));
});

const PORT = 5000;

server.listen(PORT, => console.log('Server running on port $(PORT)'));

IMPORTANT HTTP STATUS CODES

  • 1.xx Informational
  • 2.xx Success
    • 200 Success
    • 201 Created
    • 204 No Content
  • 3.xx Redirection
    • 304 Not Modified
  • 4.xx Client Error
    • 400 Bad Request
    • 401 Unauthorized
    • 404 Not Found
  • 5.xx Server Error
    • 500 Internal Server Error

HTTP REQUEST METHODS

REQUEST METHOD What is it for?
GET Retrieve Resource
POST Submit Resource
PUT / PATCH Update Resource
DELETE Delete/Destroy Resource

RESTFUL API STANDARDS

REQUEST METHOD Standard
GET /data Get data
GET /data/1 Get data with ID of 1
POST /data Add data
PUT /data/1 Update data with ID of 1
DELETE /data/1 Delete data with ID of 1

learning-and-mastering-node.js's People

Contributors

berkbuyukdurak avatar

Watchers

James Cloos avatar  avatar

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.