Giter VIP home page Giter VIP logo

express-typescript-starter's Introduction

Introduction

Project is a faster way to building a Node.js RESTful API in TypeScript.

Start use now and just focus on your business and not spending hours in project configuration.

Features

  • Beautiful Code thanks to the awesome annotations of the libraries from pleerock.
  • Dependency Injection done with the nice framework from TypeDI.
  • Simplified Database Query with the ORM TypeORM.
  • Clear Structure with different layers such as controllers, services, repositories, models, middlewares...
  • Easy Exception Handling thanks to routing-controllers.
  • Smart Validation thanks to class-validator with some nice annotations.
  • Custom Validators to validate your request even better and stricter (custom-validation-classes).
  • Basic Security Features thanks to Helmet.
  • Easy event dispatching thanks to event-dispatch.
  • Fast Database Building with simple migration from TypeORM.
  • Easy Data Seeding with our own factories.
  • Auth System thanks to jsonwebtoken.

Installation

Step 1: Set up the Development Environment

You need to set up your development environment before you can do anything.

Install Node.js and NPM

Install a MySQL database.

If you work with a mac, i recommend to use DBngin for the installation.

Step 2: Create new Project

Clone or download this project. Configure your package.json for your new project.

Then copy the .env.example file and rename it to .env. In this file you have to add your database connection information.

Create a new database with the name you have in your .env file.

Then setup your application environment.

npm install

This installs all dependencies with npm. So after that your development environment is ready to use.

Step 3: Serve your App

Go to the project dir and start your app with this npm script.

npm run dev

This starts a local server using nodemon, which will watch for any file changes and will restart the server according to these changes. The server address will be displayed to you as http://localhost:3000.

API Routes

The route prefix is /api by default, but you can change this in the .env file.

Route Description
/api/users Example entity endpoint

Database Migration

  • Run npm run typeorm migration:create {name} to create a new migration file.
  • To migrate your database run npm run typeorm migration:run.

Running Seeders

  • You may execute the npm run seed:run command to seed your database.

Pagination & Sort

Pagination and Sort are implemented on method getAll for Users, try to send an api like this: http://localhost:3000/api/users?limit=10&page=1&sortByDesc=id.

Project Structure

Name Description
dist/ Compiled source files will be placed here
src/ Source files
src/config The config directory, as the name implies, contains all of your application's configuration files.
src/api/controllers/ REST API Controllers
src/api/responses Response classes or interfaces to type json response bodies
src/api/exceptions/ Custom HttpErrors like 404 NotFound
src/api/middlewares/ Express Middlewares
src/api/models/ TypeORM Models
src/api/repositories/ Repository / DB layer
src/api/services/ Service layer
src/api/subscribers/ Event subscribers
src/api/validators/ Request classes with validation rules if the body is not equal with a model
src/api/transformers/ Class-transformer allows you to transform plain object to some instance of class and versa
src/database/factories Factory the generate fake entities
src/database/migrations Database migration scripts
src/database/seeds Seeds to create some data in the database
src/decorators/ Custom decorators like @EventDispatch
src/public/ Static assets (fonts, css, js, img).
.env.example Environment configurations

License

MIT

express-typescript-starter's People

Contributors

gentritabazi 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.