Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cham11ng/typescript-api-starter
Node.js (🤖) Express.js / PostgreSQL API in TypeScript
https://github.com/cham11ng/typescript-api-starter
api backpack chai docker docker-compose eslint express github-actions hacktoberfest jest knex knexjs migration nodejs objection objectionjs prettier seed typescript winston
Last synced: 6 days ago
JSON representation
Node.js (🤖) Express.js / PostgreSQL API in TypeScript
- Host: GitHub
- URL: https://github.com/cham11ng/typescript-api-starter
- Owner: cham11ng
- License: mit
- Created: 2018-01-27T10:36:45.000Z (almost 7 years ago)
- Default Branch: dev
- Last Pushed: 2024-09-21T06:18:59.000Z (about 2 months ago)
- Last Synced: 2024-10-15T01:41:22.267Z (22 days ago)
- Topics: api, backpack, chai, docker, docker-compose, eslint, express, github-actions, hacktoberfest, jest, knex, knexjs, migration, nodejs, objection, objectionjs, prettier, seed, typescript, winston
- Language: TypeScript
- Homepage:
- Size: 2.85 MB
- Stars: 100
- Watchers: 4
- Forks: 16
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
This is a API starter template for building a Node.js and Express.js using Typescript and PostgreSQL as database. It includes popular tools such as jsonwebtoken, joi, Knex, Objection.js, and more.
## Requirements
- [Node.js](https://yarnpkg.com/en/docs/install)
- [Yarn](https://yarnpkg.com/en/docs/install)
- [NPM](https://docs.npmjs.com/getting-started/installing-node)
- [Docker](https://docs.docker.com/install/)## Getting Started
```bash
# Clone repository
$ git clone [email protected]:cham11ng/typescript-api-starter.git$ cd
# Update database credentials
$ cp .env.example .env# Install dependencies
$ yarn install$ yarn migrate
``````bash
# Load fake data in database.
$ yarn load:fake
```Start the application.
```bash
# For production
$ yarn build# For development
$ yarn dev
```### Using Docker
```bash
$ docker compose up -d api# Make sure server is started checking logs before running this command
$ docker compose exec api sh yarn migrate
``````bash
# View logs of the container.
$ docker compose logs -f api# To stop the services.
$ docker compose stop api postgres
```## Generating Migrations and Seeds
```bash
# To create migration use `make:migration`
$ yarn make:migration create_{table_name}_table# To create seed use `make:seeder`
$ yarn make:seeder {table_name}_table_seeder
``````bash
# Example
$ yarn make:migration create_posts_table
$ yarn make:seeder post_table_seeder
```Modify migration and seeder file as per the requirement. Then finally:
```bash
# to migrate
$ yarn migrate# to seed
$ yarn seed
```## Setting up REST Client
Create a file or add following lines in `.vscode` > `settings.json` and switch an environment `Cmd/Ctrl + Shift + P` > `REST Client: Switch Environment`. Then, you can request APIs from `api.rest` file.
```json
{
"rest-client.environmentVariables": {
"$shared": {
"refreshToken": "foo",
"accessToken": "bar",
"email": "[email protected]",
"password": "secret"
},
"local": {
"host": "localhost",
"refreshToken": "{{$shared refreshToken}}",
"accessToken": "{{$shared accessToken}}",
"email": "{{$shared email}}",
"password": "{{$shared password}}"
}
}
}
```## Contributing
Feel free to send pull requests.
## License
typescript-api-starter is under [MIT License](LICENSE).