Coder Social home page Coder Social logo

nodejs-demo's Introduction

Tech stacks:

  • NodeJS, Typescript, Express
  • PostgreSQL, knex, objection
  • Jest

Start app:

To start an API HTTP server

Prerequisite

  • A PostgreSQL server (tested against v13)
  • NodeJS (tested against v12)
  • (For Docker app mode) Docker

Dev mode:

  • Install dependencies: npm i
  • Create .env file following the template file ".env.example"
  • Start app: npm run dev

Production mode:

  • Compile to production code: npm run build
  • Create .env file to the folder "/dist" following the template file ".env.example"
  • Start app: npm start

Production container mode:

<TBD: more deployment testing>

  • Build image: npm run build -t khoa/football_demo:1.0.0 .
  • Run app:
docker run -d --network=host \
  -e "DB_DBNAME=your_db" \
  -e "DB_PORT=5432" \
  -e "DB_USER=your_db_user" \
  -e "DB_PASS=your_db_password" \
  -e "DB_HOST=127.0.0.1" \
  --name khoa/football_demo:1.0.0

Test

  • Coverage: all route controllers
  • To run test, run npm test

API Documentation

<TBD: more completely done with Swagger>

  • Get clubs:
curl --location --request GET 'http://localhost:3000/api/clubs?name=fc&code=LEE&page=1'
  • Get club by ID:
curl --location --request GET 'http://localhost:3000/api/clubs/55'
  • Add a club:
curl --location --request POST 'http://localhost:3000/api/clubs' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "Hoang Anh Gia Lai 2 FC",
    "code": "HAG2",
    "country": "Vietnam"
}'
  • Update a club:
curl --location --request PUT 'http://localhost:3000/api/clubs/1' \
--header 'Content-Type: application/json' \
--data-raw '{
    "country": "Poland"
}'
  • Delete a club:
curl --location --request DELETE 'http://localhost:3000/api/clubs/34'

Notes:

  • Default API per page is 10

nodejs-demo's People

Contributors

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