Giter VIP home page Giter VIP logo

happy-server's Introduction

Happy-Server

Initialization

  • npm init

  • npm install express

  • npm install typescript -d

  • npx tsc --init

  • Changed the target at the tsconfig.json file from es5 to es2017 to reduce unnecessary convertions.

  • npm install ts-node-dev -d Is used to allow the use of typescript and node.

  • Added the dev script. Flags used:

    • Transpile-only: disable the constant auto check made by ts-node-dev.
    • Ignore-watch node_modules: disable the constant auto check made in the node modules. To start the server use npm run dev
  • npm install typeorm sqlite3

Tsconfig:

  • Set the "strictPropertyInitialization" to false for ts to not request a initial value as a initialization (this is important when making models).
  • Set "experimentalDecorators" and "emitDecoratorMetadata" to true to alow using decorators (also important when making models);

Database, ORM and typeorm

  • Created an ormconfig.json

ORM

In the ormconfig.json, it is set: * Where the database is; * The type of the database; * Where the migrations will be stored; * Where the cli should store the migrations; * Where the entites (models) are;

Typeorm

Typeorm runs in javascript by default. So, it's necessary to overwrite the default script on the package.json.

Migrations

  • Create a migration: npx typeorm migration:create -n (name_of_the_migration)
  • Run migrations: npm run typeorm migration:run
  • Revert migrations: npm run typeorm migration:revert

Multer and @types/multer

It's a middleware used to handle image and files sent to the body. (I have a long and painfull history with this middleware).

Exception error handler and express-async-errors

This module is used to handle async errors. Async errors usually take too long or sometimes doesn't return anything until a timeout happens.

Validation: yup and @types/yup

This module helps to simplify the validation of data.

Cors

Allow sites with diferents urls to access the server. It's recomended to install as dependency in production because node just allow the trasnfer of data when the the server and frontend are in the same url.

Authentication

jsonwebtoken

It's used to generate a token from a json and keep it in a session for authentication. The secret of the token is stored in a config.ts file (that's on .gitignore).

bryptjs, @types/bcryptjs

Creates a hash for the password and compares it to check if it matches.

happy-server's People

Contributors

erick-oliveira-et avatar

Stargazers

Lucas Pinheiro Moraes avatar

Watchers

 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.