Code Monkey home page Code Monkey logo

api-koa-typescript-starter's Introduction

Rangle Koa-starter for Typescript

Quick Start

This starter works with npm or yarn.

Install:

yarn # or npm install

Run in dev mode, restarting the server on file changes:

yarn dev

Run unit tests:

yarn test

Run in prod mode, not daemonized, with staging config (suitable for Heroku):

yarn build
yarn start

Start/stop in prod mode, daemonized, with local config:

yarn build
yarn local:start
yarn local:stop

Start/stop in prod mode, daemonized mode, with staging config:

yarn build
yarn staging:start
yarn staging:stop

Build (or update) the API documentation to api.html in the root:

yarn raml

Things of note for the TypeScript port

As part of the port, all of the files have been updated to define and import ES6 modules. The typings in relation to the original Rangle Koa starter are straightforward, with a few exceptions.

The first of those is the request-id-generator.ts middleware. It adds a new field to the Koa context, so it uses declaration merging to add it as a new optional field to both the context itself and the request headers. This lets the rest of the code access this field without errors, or needing to fallback to any.

The second of the use of a generic type parameter in the validateParams middleware constructor function. This adds a small amount of intra-module type checking for validate-params.ts, but unfortunately the Typescript compiler is currently unable to check that the provided path actually produces a value with the type the validator expects when navigated from the context object.

The project-env.ts file defines a common interface for the options loaded from the different modules with environment options. These modules are dynamically loaded with require, so the TypeScript compiler is also unable to check that they indeed define the proper interface.

The package.json file now defines a build target to compile TypeScript files to JavaScript. It also changes the dev target to run ts-node-dev instead of nodemon, for faster reloading from changes in the TypeScript files while in development mode. The TypeScript compiler targets ES2017, as that is fully supported by both the current (version 10) and last (version 9) major versions of Node.js.

The thing of note is not related to TypeScript per se, but the implementation of the outgoingRequest service in outgoing-request-service.ts was changed from promises to async/await.

api-koa-typescript-starter's People

Contributors

brendanfdmoore avatar greenkeeperio-bot avatar jakxz avatar mascarenhas avatar odziem avatar sethdavenport avatar troyt-42 avatar

Watchers

 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.