NodeJS and ExpressJS Tutorial: Building REST APIs, Lecture notes of Italian Language

An introduction to building rest apis using nodejs and expressjs. It covers installation, creating get and post requests, working with routers and handlers, and connecting to a mysql database. The guide includes code snippets and instructions for setting up a development environment and testing api endpoints with postman. It also references external resources for further learning, making it a practical resource for web development students. Useful for understanding the basics of creating a rest api using node.js and express, providing a step-by-step guide to setting up the environment, creating routes, and connecting to a database. It includes practical examples and references to external resources, making it a valuable resource for beginners in web development.

Typology: Lecture notes

2024/2025

Uploaded on 06/13/2025

le-quang-nguyen
le-quang-nguyen 🇸🇬

1 document

1 / 29

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Introduction to NodeJS
Instructor: Nguyễn Trung Nghĩa
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d

Partial preview of the text

Download NodeJS and ExpressJS Tutorial: Building REST APIs and more Lecture notes Italian Language in PDF only on Docsity!

Introduction to NodeJS

Instructor: Nguyễn Trung Nghĩa

REST API VS Web Services

Tools

Installation

Node.js — Download Node.js®

(nodejs.org)

Create project

Install packages npm i mysql2 express npm i D nodemon

Create Server import express from "express" // import ExpressJS framreword const app = express(); // use the expressJS const PORT = process.env.POST || 5000 ; // define PORT app.listen(PORT, () => console.log("Server Open At port: ", PORT));

Create GET request import express from "express" // const app = express(); // use the expressJS const PORT = process.env.POST || 5000 ; // define PORT app.listen(PORT, () => console.log("Server Open At port: ", PORT)); app.get("/", (req, res, next) => { console.log(req.method) res.send("Hello"); // send response }); // create GET request

Work with Routes

Create Routes & Handlers export const getAllProducts = async (req, res) => { return res.send("GET ALL PRODUCTS"); }; import { Router } from "express"; import { getAllProducts } from "../handlers/index.js"; const appRouter = Router(); appRouter.get("/", getAllProducts) export default appRouter;

Time to test

So, what happen after all?

Let’s complete Handlers export const getAllProducts = async (req, res) => { return res.send("GET ALL PRODUCTS"); }; export const getProduct = async (req, res) => {}; export const createProduct = async (req, res) => {}; export const updateProduct = async (req, res) => {}; export const deleteProuct = async (req, res) => {};

V. Working with DB

If you use MAC run mySQL by docker