Code Monkey home page Code Monkey logo

nodejses6's Introduction

Express with ES6 (RestAPI) - Defect Machine

An skeleton express app that allows you to use ES6 syntax. Generated by express-generator cli.

How to run

Before anything else, you must have node installed on your machine.

Config Environments such as Database connection info, port and etc

In root of project config folder you can change envs as dev,prod,stag,test

Before run server you must config Postgresql server configuration info in config => development.json:

database:{
  "host": "localhost",
  "user": "postgres",
  "password": "123456",
  "database": "NodeJsDb",
  "port":"5432"
}

Project Structure : Domain Driven + OOP + SOLID

Request life cycle;

    requestA fire +++>>> api/v1/defect
    --> Validation by Joi libraries as middleware in routes config;
    ---> After pass by validation process handleing by Controller
    ----> All of exception handle in this layer to CustomExceptionHandler as middleware
          (send a full friendly error detail to response) 
    -----> if there is not error 
    ------> Request sent to PresentionLayer as Logic and Process all logic flow on request 
    ------->  PresentionLayer for do all transaction use defectService, machineService and etc as services
    --------> Services communicated with DomainLayer Or Data as Repositories like defectRepository, machineRepository
    ---------> All of Data Logic must be handle by repositories 
    ----------> Repositories use DbManager to do transaction like CRUD on Database
    
    Mapping Classes From DomainLayer (Data/Model) to PresentationLayer (View):
     ---> mapped DbModel (QueryResultModel) to ViewModel (ApiResponseModel)
   
    Mapping Classes From PresentationLayer (View) to DomainLayer (Data/Model):
     ---> mapped ViewModel (ApiRequestModel) to DbModel (QueryParamModel)
    
    Done!

Init Database

Use SQL Create Queries in src/domain/data/example-db.sql to create your Postgresql DB

Running Dev Server

Add "type":"module" to package.json file and after stop Dev Server for build should remove it.

Then, run on your terminal npm run watch:dev, the server will restart everytime you make a change in your code.

Or if you want without watching you can run on your terminal npm-run-all build server

Running Unit Tests (Jest)

-Unit-Tests:

Run on your terminal npm test-unit.

-Integration-Tests:

Run on your terminal npm test-integration.

Also, You can see coverage of test in coverage folder of root project

Running Production Server

For stuff like heroku deployment, aws elasticbeanstalk, run npm run start

Logs Service (Winston)

All logs as Debug, Info, Error, Warning generate on Logs folder as file when project run

Use Postman for communicate with API

Defect.postman_collection.json

Other scripts

  • transpile - convert es6 and beyond code to es5 to a folder named dist-server
  • clean - delete transpiled folder
  • build - clean and transpile
  • server - start transpile code

nodejses6's People

Contributors

pmonfared avatar

Watchers

James Cloos avatar  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.