Please enable JavaScript.
Coggle requires JavaScript to display documents.
Node https://github.com/Junior-dev-Track/31-backend-http-and-express…
Vocabulary
Node.js® is a free, open-source, cross-platform JavaScript runtime environment that lets developers create servers, web apps, command line tools and scripts. https://nodejs.org/en/learn/getting-started/introduction-to-nodejs
CPU The Central Processing Unit (CPU) is the primary component of a computer that acts as its “control center.” The CPU, also referred to as the “central” or “main” processor, is a complex set of electronic circuitry that runs the machine's operating system and apps.
Package Manager
or package-management system is a collection of software tools that automates the process of installing, upgrading, configuring, and removing computer programs for a computer in a consistent manner.
-
What do we use Node for?
REST API's.
Real Time Services (chat apps, live changes or updates).
CRUD Apps (Blogs, E-shops, Social platforms)
Initializing Go to your project folder (where we created the server.js file), and initialize your package.json with the command npm init.
npm run test
Running server.js-npm run start if you run this command, it will execute and stop once it's done. In a development environment, this is not ideal, that would mean we need to re-execute that command each time we make a change in order to check if it works as intended.
Running server.js in developmentto keep our node runtime from stopping during the development of our project use -->
-
By default, there is a script test in your package.json file.
Core modules
Node.js has a set of core modules, also called Build-in modules.
These modules can be used without any further installation.
__dirname and __filename! Both are what we call "environment variables" dirname: the absolute path to the current directory; filename: the absolute path to the current file (__dirname + file)
-
const path = require('path') // plain Javascript
or import path from "path"; // ES6 (modern Javascript) (not recommended when using environment variables)
const fs = require('fs') // plain Javascript or
import fs from "fs"; // ES6 (modern Javascript) (not recommended when using environment variables)
http allows Node.js to transfer data over the Hyper Text Transfer Protocol (HTTP). Import: const http = require('http') // plain Javascript
We need to create a server object by using our http module: // This server
will receive data.
const server = http.createServer()
now that we have the server as an object stored in our variable server, we can make the server watch for certain events by using the server.on() method.
his method will expect two arguments: server.on(argument01, argument02)
server.on("request", (request, response) => {})
argument01: is the type of event it needs to listen to, in this case a request event -> when the server get's a request.
argument02: is a callback function, that will execute something when the event is triggered.
Express is the most popular Node web framework, and is the underlying library for a number of other popular Node web frameworks.
-
-
Routing refers to determining how an application responds to a client request to a particular endpoint, which is a URI (or path) and a specific HTTP request method (GET, POST, and so on).
Basic routing Each route can have one or more handler functions, which are executed when the route is matched.
-
-
JSONWEBTOKENS
-
const express = require('express');
const jwt = require('jsonwebtoken');
const dotenv = require('dotenv');
-
-
-
-
-
-
-