Go to file Use this template
Sambo Chea c999b4a8f6
All checks were successful
continuous-integration/drone/push Build is passing
Fixed dockerfile build missing yarn
2021-09-16 18:25:35 +07:00
.husky Updated husky and install for prettier 2021-09-13 20:28:43 +07:00
packages Updated readme 2021-09-16 18:18:13 +07:00
src Add express server from module and updated the server and config 2021-09-16 18:14:49 +07:00
.dockerignore Task: Add Dockerfile and support DroneCI 2021-09-13 17:53:12 +07:00
.drone.yml Forgot yarn command 2021-09-16 18:20:52 +07:00
.env Add server port in env 2021-09-13 20:50:53 +07:00
.eslintrc.js Task: Add express and nodejs application with TypeScript , Prettier and Husky 2021-09-13 17:49:01 +07:00
.gitignore Updated package and gitignore 2021-09-13 20:53:05 +07:00
.gitmodules Add express server from module and updated the server and config 2021-09-16 18:14:49 +07:00
.prettierrc.json Task: Add express and nodejs application with TypeScript , Prettier and Husky 2021-09-13 17:49:01 +07:00
Dockerfile Fixed dockerfile build missing yarn 2021-09-16 18:25:35 +07:00
lerna.json Task: Updated lerna.json and add yarn workspaces and ts-common package and fixed the tsconfig 2021-09-13 20:19:28 +07:00
LICENSE Initial commit 2021-09-13 17:04:49 +07:00
package.json Fixed lerna build 2021-09-16 18:25:11 +07:00
README.md Updated readme 2021-09-16 18:18:13 +07:00
tsconfig.json Task: Fixed package json for yarn serve and fixed tsconfig for build with all packages to src only 2021-09-15 08:52:20 +07:00

Express Nodejs App

  • Nodejs
  • Express
  • TypeScript
  • Prettier
  • ESLint
  • Docker
  • DroneCI
  • Lerna Support
  • Support decorators

Quickstart

  • Clone repository
git clone https://git.cubetiqs.com/CUBETIQ/express-nodejs-app.git --recurse-submodules --remote-submodules
  • Update an existed repository
git submodule update --init --remote
  • Add Packages
mkdir packages && git submodule add https://git.cubetiqs.com/CUBETIQ/ts-common.git packages/ts-common && git submodule add https://git.cubetiqs.com/CUBETIQ/cubetiq-express-server.git packages/cubetiq-express-server
  • Install and Build Packages
yarn && npx lerna run build
  • Start
yarn start
  • Navigate
curl http://localhost:3000/info
  • Response
{
    "startedAt": "2021-09-13T13:21:04.184Z",
    "message": "Instance id: presenter#143470",
    "status": "OK"
}

Build application

yarn build

Quick Register Controller

  • Add new controller src/controller/home.controller.ts
import { Request, Response } from "express"
import { Controller, Get, Post, Delete } from "../decorators"

const data: any[] = []

@Controller("/home")
export default class HomeController {
    constructor() {}

    @Get()
    public get(req: Request, res: Response) {
        res.json(data)
    }

    @Post()
    public create(req: Request, res: Response) {
        const body = req.body
        if (body == null) {
            return res.status(400).json({
                status: 400,
                message: "Data is required",
            })
        }

        data.push(body)
        res.json({
            message: "Data created successfully",
            body: body,
        })
    }

    @Delete("/:id")
    public get(req: Request, res: Response) {
        const id = req.params.id
        res.json({
            id: id,
        })
    }
}
  • Register controller into index.ts (src/controllers/index.ts)
import IndexController from "./index.controller"
import PersonController from "./person.controller"
import HomeController from "./home.controller"

export const controllers = [IndexController, PersonController, HomeController]
  • Output registered routes
┌─────────┬──────────────────────┬─────────────────────────────────┐
 (index)          api                       handler             
├─────────┼──────────────────────┼─────────────────────────────────┤
    0         'GET /hello'          'IndexController.index'     
    1      'GET /hello/:name'       'IndexController.hello'     
    2        'GET /person'       'PersonController.getPersons'  
    3        'POST /person'     'PersonController.createPerson' 
    4     'DELETE /person/:id'  'PersonController.deletePerson' 
└─────────┴──────────────────────┴─────────────────────────────────┘

Contributors