Skip to content

carlosflorencio/typescript-api-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

styled with prettier tested with jest TypeScript David

API Template using Typescript

Custom API description here.

Already configured:

  • typescript: compiles to a build folder and has a task to watch and compile, comes with some @types in the package.json
  • jest: already configured to run and debug typescript tests, with a route test example (using supertest)
  • log4js: logs app and express requests to stdout, easily configured to log to a file
  • prettier: forget about indentation, runs before a commit
  • docker: already configured to build and run the app

Requirements

  • node (using v8)
  • yarn (faster than npm)

Environment variables

  • EXAMPLE_VAR optional - some app secret

Environment variables can be set in the .env file (rename the .env.example to .env) or in the operative system vars.

Variables in the .env file do not override the system variables if already exists with the same name.

Instructions to develop

  • yarn install - installs the dependencies
  • yarn start - watch's .ts files and compiles to build folder then the server is reloaded at localhost:3000
  • yarn test - runs the tests with jest (typescript tests)
  • yarn build - compiles .ts files to build folder
  • yarn serve - starts the app (node build/bin/server.js)
  • yarn prettier - runs prettier to prettify the code (also runs before each commit)

Docker instructions

  • docker build -t myapi .
  • docker run -d -p 80:3000 myapi

Passing environment variables:

  • docker run -d -p 80:3000 -e "MYVAR=apikey" myapi

License

MIT

About

Template for creating an API server using Typescript

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published