Skip to content

⚡️🔥 Deep learn and build typescript project from basic until using node framework

License

Notifications You must be signed in to change notification settings

nuhptr/typescript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Typescript-Learn-Code

Typescript Repository Code from basic until expert

Folder Structure

Typescript Mas Nusendra

  1. Basic
  2. Design Pattern
  3. OOP
  4. OOP Case
  5. TODO Express

Typescript my learn

  1. Basics

  2. Object Oriented Programming

  3. ts express

Learn init ts using typescript

  1. ts with axios

Learn how to use axios with typescript

Typescript Rest API

  1. User API Spec
  2. Address API Spec
  3. Contact API Spec

and many more to create a restfull api using typescript and nodejs with express

Configuration Typescript Project

npm init -y (if you don't have package.json)
pnpm add typescript -D
npx tsc --init

add additional package

add script to package.json

   "scripts": {
      "tsc" : "rm -rf build/ && tsc",
      "ts" : "rm -rf build/ && tsc -w",
      "dev" : "nodemon ./build"
   }

Then konfiguration in tsconfig.json

   "allowJs": true,
   "outDir": "./build",
   "forceConsistentCasingInFileNames": false,

Run Typescript Build

ctrl + shift + b -> tsc:build - tsconfig.json

Run nodemon

pnpm dev

Express Dependencies

  • body-parser - pnpm add body-parser (parse incoming request bodies in a middleware before your handlers, available under the req.body property.)

  • morgan - pnpm add morgan (HTTP request logger middleware for node.js) / winston - pnpm add winston (A logger for just about everything.)

  • express - pnpm add express (nodejs framework)

  • helmet - pnpm add helmet (secure Express apps by setting HTTP response headers.)

  • cors - pnpm add cors (a Connect/Express middleware)

  • compression - pnpm add compression (compress response)

  • dotenv - pnpm add dotenv (save credentials from environment)

  • sequelize - pnpm add sequelize (Promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite and Microsoft SQL Server.)

  • sequelize-cli - pnpm add sequelize-cli (The Sequelize Command Line Interface (CLI))

  • mysql2 - pnpm add mysql2 (MySQL client for Node.js with focus on performance. Supports prepared statements, non-utf8 encodings, binary log protocol, compression, ssl)

  • bcrypt - pnpm add bcrypt (A library to help you hash passwords.)

  • express-validator - pnpm add express-validator (An express.js middleware for validator)

  • jsonwebtoken - pnpm add jsonwebtoken (An implementation of JSON Web Tokens)

Setup Sequelize ORM

  • Add Dependencies
pnpm add mysql2 sequelize sequelize-cli
  • Add .sequelizerc in project
// .sequelizerc
const path = require("path")
require("dotenv").config()

if (process.env.NODE_ENV == "development") {
    module.exports = {
        config: path.resolve("src/config", "database.js"),
        "models-path": path.resolve("src/db", "models"),
        "seeders-path": path.resolve("src/db", "seeders"),
        "migrations-path": path.resolve("src/db", "migrations"),
    }
} else {
    module.exports = {
        config: path.resolve("build/config", "database.js"),
        "models-path": path.resolve("build/db", "models"),
        "seeders-path": path.resolve("build/db", "seeders"),
        "migrations-path": path.resolve("build/db", "migrations"),
    }
}
  • Init sequelize-cli
npx sequelize-cli init
  • Create model dan migrate
npx sequelize-cli model:generate --name user --attributes username:string,password:string --underscored
  • Migrate database to MySql
npx sequelize-cli db:migrate
# untuk membalikan migrasi
npx sequelize-cli db:undo
  • Add Development Dependencies
pnpm add @types/validator -D
pnpm add @types/bluebird -D

About

⚡️🔥 Deep learn and build typescript project from basic until using node framework

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published