Giter Site home page Giter Site logo

wpcodevo / node_typeorm Goto Github PK

View Code? Open in Web Editor NEW
89.0 1.0 50.0 637 KB

In this article, you'll learn how to build CRUD RESTful API with Node.js, ExpressJs, TypeORM, and PostgreSQL. We will define the database schema with TypeORM and run the migration command to push the TypeORM schema to the database. Next, we will create higher-level CRUD function to perform the CRUD operations.

Home Page: https://codevoweb.com/node-express-typeorm-postgresql-rest-api

Makefile 0.65% TypeScript 74.36% Shell 5.20% Pug 19.80%
jwt jwt-auth jwt-authentication jwt-tokens node node-js nodejs postgres postgresql postgresql-database

node_typeorm's Introduction

API with Node.js + PostgreSQL + TypeORM

API with Node.js + PostgreSQL + TypeORM: Project Setup

API with Node.js + PostgreSQL + TypeORM: Project Setup

In this article, you'll learn how to set up a Node.js project with TypeScript, ExpressJs, PostgreSQL, TypeORM, and Redis. Also, you will learn how to run Postgres and Redis servers with Docker.

Topics Covered

  • Setup Node.js with Express, PostgreSQL, Redis, and TypeORM
    • Creating PostgreSQL and Redis Database with Docker
    • Setup Environment Variables with Dotenv
  • Initialize a New TypeORM Express App
  • Connecting an Express application with PostgreSQL
  • Connecting an ExpressJs application to Redis
  • Run the Express Server

Read the entire article here: https://codevoweb.com/api-node-postgresql-typeorm-project-setup

API with Node.js + PostgreSQL + TypeORM: JWT Authentication

API with Node.js + PostgreSQL + TypeORM: JWT Authentication

This article will teach you how to implement JSON Web Token (JWT) Authentication with Node.js, PostgreSQL, TypeORM, ExpressJs, Redis, Docker, and Docker-compose. We will implement the assymetric (RS256 algorithm) JSON Web Token authentication manually without using any Node.js authentication library like PassportJs.

Topics Covered

  • List the Node.js API Routes
  • User Login and Register Flow with JWT Authentication
  • Defining Base and User Entities with TypeORM
  • Defining Zod Schemas to Validate Request Body
  • Create Middleware to Parse Zod Schema
  • Password Management with Bcrypt
  • Create Services to Interact with the Database
  • Asymmetric Encryption (RS256 algorithm) Json Web Tokens
  • Service to Sign Access and Refresh Tokens
  • Error Handling in Express
  • Create Authentication Route Controllers
  • Create User Route Controller
  • Create Authentication Middleware Guard
  • Create the API Routes
    • Authentication Routes
    • User Routes
  • Add the Routes to the Express Middleware Stack
  • Run Database Migrations with TypeORM
  • Inspect the Data with VS Code MySQL Extension

Read the entire article here: https://codevoweb.com/api-node-postgresql-typeorm-jwt-authentication

API with Node.js + PostgreSQL + TypeORM: Send Emails

API with Node.js + PostgreSQL + TypeORM: Send Emails

In this article, you'll learn how to send development and production-ready emails with Nodemailer, Node.js, PostgreSQL, and TypeORM. We will include the Email verification feature in the API to ensure the users provide valid email addresses during the account registration process.

Topics Covered

  • Setting up Express.js with Pug Templating Engine
  • Create a Utility Class to Send Emails
    • Require the Nodemailer Credentials
    • Define the Email Class Attributes
    • Create a Nodemailer Transporter
    • Create a Method to Generate the Email Templates
    • Create a Method to Send the Emails
  • Creating the Email Templates with Pug
  • Create the User Entity with TypeORM
  • Database Schema Migration with TypeORM
  • Update the User Register Controller
  • Add a Controller to Verify the Email
  • Update the Login Controller

Read the entire article here: https://codevoweb.com/api-node-postgresql-typeorm-send-emails

Node.js, Express, TypeORM, PostgreSQL: CRUD Rest API

Node.js, Express, TypeORM, PostgreSQL: CRUD Rest API

In this article, you'll learn how to build CRUD RESTful API with Node.js, ExpressJs, TypeORM, and PostgreSQL. We will define the database schema with TypeORM and run the migration command to push the TypeORM schema to the database. Next, we will create higher-level CRUD function to perform the CRUD operations.

Topics Covered

  • Node.js, TypeORM, PostgreSQL CRUD RESTful API Overview
  • Project Structure
  • Model Data with TypeORM and PostgreSQL
    • Define a Base Entity
    • Add One-to-Many Relationship to User Entity
    • Complete User Entity
    • Create a Post Entity
  • Create Validation Schemas with Zod
  • Create Services to Communicate with Database
  • Create Route Controllers
    • Create a New Post Controller
    • Get a Single Post Controller
    • Get All Posts Controller
    • Update a Single Post Controller
    • Delete a Single Post Controller
  • Create Routes with Express
  • Add the Routes to the Express Middleware Pipeline
  • Run Database Migration with TypeORM

Read the entire article here: https://codevoweb.com/node-express-typeorm-postgresql-rest-api

Node.js and PostgreSQL: Upload and Resize Multiple Images

Node.js and PostgreSQL: Upload and Resize Multiple Images

In this article, you'll learn how to upload and resize single and multiple images with Node.js, TypeScript, Multer, and Sharp. The Node.js API will run on an Express.js HTTP server and use PostgreSQL database.

Topics Covered

  • Upload Single Image With Multer
    • Using Multer to Upload a Single Image
    • Route Handler Functions
  • Upload Single Image with Multer and Sharp
    • Using Multer to Upload a Single Image
    • Using Sharp to Resize a Single Image
  • Create the API Route Handlers
  • Upload Multiple Images with Multer and Sharp
    • Using Multer to Upload Multiple Images
    • Using Sharp to Resize Multiple Images
      • Processing a single file
      • Processing multiple files
    • Create the Route Functions
  • Frontend for Uploading Either Single or Multiple Images

Read the entire article here: https://codevoweb.com/node-postgresql-upload-resize-multiple-images

node_typeorm's People

Contributors

wpcodevo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

node_typeorm's Issues

Failed to submit a post

Merry Chrismas. First, thank you for sharing these nice tutorials. I have learned a lot from them.

Here is one issue I found when I was playing with the example. It seems createPostSchema can not be used to validate the multipart form when submitting a post. Below are the request and response I copied from Chrome.

curl 'http://localhost:8000/api/posts' \ -H 'Accept: application/json, text/plain, */*' \ -H 'Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7' \ -H 'Cache-Control: no-cache' \ -H 'Connection: keep-alive' \ -H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryGD4n9kzBBiBxgNpT' \ -H 'Cookie: access_token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZWU3ZDVmNy0zZjNlLTRmNDctYTVhMi01NDNhYTFlNjlmZjUiLCJpYXQiOjE2NzE5NDA0OTQsImV4cCI6MTY3MTk0MTM5NH0.BhqhuOq4G0SGUZWN7AeHtbukh6AlpqFv2VLgbsVa9Rr8aAeXgyjfINWMJAXs7bOTMfqAh7DZGmr35f5FFv5mLA; refresh_token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZWU3ZDVmNy0zZjNlLTRmNDctYTVhMi01NDNhYTFlNjlmZjUiLCJpYXQiOjE2NzE5NDA0OTQsImV4cCI6MTY3MTk0NDA5NH0.YdXK-ZifORB01uxM8UC-B09FZ_fWoo5q29vaH6BZQuvlSx_E0rPcJqbTEuWvjYP3h-h6LV5U2xI7iwuQQWHMTw; logged_in=true' \ -H 'Origin: http://localhost:3000' \ -H 'Pragma: no-cache' \ -H 'Referer: http://localhost:3000/' \ -H 'Sec-Fetch-Dest: empty' \ -H 'Sec-Fetch-Mode: cors' \ -H 'Sec-Fetch-Site: same-site' \ -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36' \ -H 'sec-ch-ua: "Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108"' \ -H 'sec-ch-ua-mobile: ?0' \ -H 'sec-ch-ua-platform: "macOS"' \ --data-raw $'------WebKitFormBoundaryGD4n9kzBBiBxgNpT\r\nContent-Disposition: form-data; name="image"; filename="bio picture self.png"\r\nContent-Type: image/png\r\n\r\n\r\n------WebKitFormBoundaryGD4n9kzBBiBxgNpT\r\nContent-Disposition: form-data; name="data"\r\n\r\n{"title":"post title","content":"post details","category":"category","image":{}}\r\n------WebKitFormBoundaryGD4n9kzBBiBxgNpT--\r\n' \ --compressed

The response from the server shows title is undefined.

{"status":"fail","errors":[{"code":"invalid_type","expected":"string","received":"undefined","path":["body","title"],"message":"Title is required"},{"code":"invalid_type","expected":"string","received":"undefined","path":["body","content"],"message":"Content is required"}]}

Take to next level

Next, create a database based on the user info. (call it Create Project). Then get a pg connection string.

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.