{"id":18563470,"url":"https://github.com/henry781/ts-node-server","last_synced_at":"2025-06-13T12:32:33.941Z","repository":{"id":33397642,"uuid":"158074536","full_name":"henry781/ts-node-server","owner":"henry781","description":"[WIP] Everything you need to build a Node webservice in Typescript","archived":false,"fork":false,"pushed_at":"2023-01-23T21:57:25.000Z","size":1452,"stargazers_count":3,"open_issues_count":6,"forks_count":3,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-11T18:46:32.075Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/henry781.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-18T10:59:04.000Z","updated_at":"2023-12-11T17:43:31.000Z","dependencies_parsed_at":"2023-02-13T03:45:16.699Z","dependency_job_id":null,"html_url":"https://github.com/henry781/ts-node-server","commit_stats":null,"previous_names":[],"tags_count":89,"template":false,"template_full_name":null,"purl":"pkg:github/henry781/ts-node-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henry781%2Fts-node-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henry781%2Fts-node-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henry781%2Fts-node-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henry781%2Fts-node-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/henry781","download_url":"https://codeload.github.com/henry781/ts-node-server/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henry781%2Fts-node-server/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259645005,"owners_count":22889515,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T22:12:45.259Z","updated_at":"2025-06-13T12:32:33.897Z","avatar_url":"https://github.com/henry781.png","language":"TypeScript","readme":"# ts-node-server [WIP]\n[![Build Status](https://travis-ci.com/henry781/ts-node-server.svg?branch=master)](https://travis-ci.com/henry781/ts-node-server)\n\nts-node-server is node framework for developing RESTful web services in Typescript.\n\nIt pulls together some of the best node libraries :\n\n* [Fastify](https://github.com/fastify/fastify) : Fast and low overhead web framework, for Node.js\n\n* [Pino](https://github.com/pinojs/pino) : Super fast, all natural JSON logger for Node.js\n\n* [Inversify](https://github.com/inversify/InversifyJS) : A powerful and lightweight inversion of control container for JavaScript \u0026 Node.js apps powered by TypeScript.\n\n* [Swagger UI](https://github.com/swagger-api/swagger-ui) : A collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.\n\n* [MongoDB driver](https://github.com/mongodb/node-mongodb-native) : Mongo DB Native NodeJS Driver\n\n## Features\n\n### Route decorators\n\nts-node-server use decorators to build *fastify* routes. \n\n```\n@controller('/v1/users')\nexport class UserController {\n\n    @httpGet(':name')\n    public async get(@pathParam('name')name: string) {\n    }\n\n    @httpPost()\n    public async create(@queryParam('clone')clone: boolean) {\n    }\n```\n\n### Type validation\n\nts-node-server use *[tipify](https://github.com/henry781/tipify)* to validate, serialize and deserialize. It ensures that no property can be accidentally exposed.\n\n```\n@jsonObject()\nexport class StellarSystem {\n\n    @jsonProperty('_id', ObjectIdConverter)\n    private _id?: string;\n\n    @jsonProperty('name')\n    private _name?: string;\n\n    @jsonProperty('planets', [Planet])\n    private _planets?: Planet[];\n} \n```\n\n### Swagger generator\n\nts-node-server use route decorators and tipify decorators to build a swagger configuration.\n\n### Metrics\n\nts-node-server imports [fastify-metrics](https://github.com/fastify/fastify-metrics) and exposes all your app metrics at `/metrics`.\n\n### Healthcheck\n\nts-node-server provides an healthcheck (`/healthcheck`). You can add more checks by extending `Healthcheck` class :\n\n```\n@injectable()\nexport class MongoHealthcheck implements Healthcheck {\n\n    constructor() {\n    }\n\n    public getName(): string {\n        return 'mongodb';\n    }\n\n    public check(): Promise\u003cHealthcheckResult\u003e {\n        return {\n            true,\n            'content'\n        };\n    }\n}\n```\n\n### Authentication\n\n#### Basic authentication\n\n```\nconst server = new Server({\n    container: container,\n    auth: {\n        basic: {\n            'demo': {\n                password: 'password',\n                roles: ['admin']\n            }\n        }\n    }\n});\n```\n\n#### JWT authentication\n\n```\nconst server = new Server({\n    container: container,\n    auth: {\n        jwt: {\n            authorizationUrl: 'http://localhost:9000/auth/realms/master/protocol/openid-connect/auth?nonce=',\n            certificate: '.......CONTENT.......',\n            application: 'test'\n        }\n    }\n});\n```\n\n#### Protect a route\n\nProtect a route using auth options:\n```\n@httpGet({ url: '/:name', auth: ['jwt', 'basic'] })\npublic async get(@pathParam('name')name: string) {\n    ...\n}\n```\n\nAllow only a list of roles to access to a route:\n```\n@httpGet({ url: '/:name', auth: { jwt: { role: ['admin'] } })\npublic async get(@pathParam('name')name: string) {\n    ...\n}\n```\n\n#### Get connected user\n```\n@httpGet({ url: '/:name', auth: 'jwt')\npublic async get(@pathParam('name')name: string, @auth()user: Principal {\n    const logger = getLogger('get', this);\n    logger.info('my name is', user.firstname, user.lastname, 'and my login is', user.login);\n    ...\n}\n```\n\n### Generic client\n\nts-node-service provides GenericClient which is wrapper around *request*.\nGenericClient features:\n* Serialization / Deserialization with *tipify*\n* Error management and expected status\n* Authorization header format form a token or principal\n* Add *request-id* header to the request\n\n```\nexport class UserClient extends GenericClient {\n\n    public getUser(name: string) : Promise\u003cUser\u003e {\n        const options : RequestOptions\u003cUser\u003e = {\n            expectedStatus: 200,\n            principal: principal,\n            deserializeType: User\n        };\n        return this.get\u003cUser\u003e('http://localhost/api/users/' + name, options);\n    }\n}\n```\n\n### Logging\n\n#### Get request logger\n\nWith fastify a logger is created for every request, it allows to add a request id to every log.\nTo access to this logger:\n```\nconst logger = getLogger();\nlogger.info('hello');\n```\n\n## Usage\n\nSee [ts-node-server-starter](https://github.com/henry781/ts-node-server-starter) for an example.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenry781%2Fts-node-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhenry781%2Fts-node-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenry781%2Fts-node-server/lists"}