Skip to content
Starter kit for Node.js server written in TypeScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.dockerignore
.editorconfig
.gitignore
Dockerfile
README.md
ormconfig.json
package.json
tsconfig.json
yarn.lock

README.md

Node.js Server with TypeScript

We are going to use TypeScript Express.js and TypeORM to create an enterprise level REST API server. The objective is to create a repository that you can use as bases for your projects.

Development

Prerequisites: Node.js (>=6.x, 10.x preferred), npm version 3+, yarn and Git.

Fetch dependencies:

$ yarn

Start nodemon server, compile TypeScript and watch files:

$ tsc && yarn start

Production

Prerequisites: only DockerCE

Those commands will run your server at port 3000:

$ docker build -t fptu-ts .
$ docker run -d --name fptu-ts -p 3000:3000 fptu-ts:latest

Production image size is about ~90MB.

Concept

Inspired from JavaEE Spring Boot:

Entity:

import {
    Entity,
    PrimaryGeneratedColumn,
    Column,
    UpdateDateColumn
} from "typeorm";

@Entity()
export class TrackingEntity {
    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    userAgent: string;

    @Column()
    senderToken: string;

    @Column()
    @UpdateDateColumn()
    updateAt: Date;
}

Controller:

import { JsonController, Get } from "routing-controllers";
import { getRepository } from "typeorm";
import { Tracking, TrackingEntity } from "../entity/Tracking";

@JsonController("/trackings")
class TrackingController {
    @Get("/")
    async getTrackings(): Promise<Tracking[]> {
        const trackingRepository = getRepository(TrackingEntity);
        const trackings = await trackingRepository.find({
            select: ["id", "senderToken", "updateAt", "userAgent"]
        });

        return trackings;
    }
}

export default TrackingController;
You can’t perform that action at this time.