Skip to content

A back-end based on the RealWorld API spec using Typescript, PostgreSQL, Node, Express, and Docker.

License

Notifications You must be signed in to change notification settings

mjftw/typescript-realworld-backend

Repository files navigation

RealWorld Example App

Typescript codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API

The RealWorld examples project provides a front end and back end spec to be implemented in many different languages and technologies that allows you to create a Conduit clone.

This project will follow the RealWorld backend API spec, making it compatible with any of the RealWorld front end implementations.

This codebase was created to demonstrate a fully fledged fullstack application built with Typescript and Express including CRUD operations, authentication, routing, pagination, and more.

We've gone to great lengths to adhere to the Typescript community styleguides & best practices.

For more information on how to this works with other frontends/backends, head over to the RealWorld repo.

How it works

This implementation uses Typescript, Node, Express, PostgreSQL, and Docker.

The app is packaged with Docker and can be run with docker compose.

Server configuration

A number of configuration environment variables are used to configure the app.

| Variable name | Description | Required for app | Example | | ---------------- | ------------------------------------------- | ---------------- | | APP_PORT | Port to expose the app on | Yes | 4000 | | JWT_SECRET | Secret to use for signing JWT auth tokens | Yes | arandomstring | | DB_USERNAME | Username to be used for postgreSQL database | Yes | postgres | | DB_PASSWORD | Password to be used for postgreSQL database | Yes | postgres | | DB_NAME | Name to be used for postgreSQL database | Yes | postgres | | DB_PORT | Port to expose the database on | Yes | 5432 | | PGADMIN_EMAIL | Pgadmin4 database admin login email | No | [email protected] | | PGADMIN_PASSWORD | Pgadmin4 database admin login password | No | supersecret | | PGADMIN_PORT | Port to expose the Pgadmin4 on | No | 443 |

Getting started

The app can be run standalone with Node.js, or the whole stack can be run using Docker.

Run the stack

Dependencies

First of all, make sure you have Docker and Docker Compose installed. Installation instructions can be found at:

If installing for the first time, make sure to check successful installation with:

$ docker -v
Docker version 19.03.13, build 4484c46d9d

$ docker-compose -v
docker-compose version 1.27.4, build 40524192

(Your versions may vary)

Build and run

To build the app Docker container run:

docker-compose up

The first step is to build the app's Docker image:

docker-compose build

Before running the app a number of environment variables must be set. See Server configuration section for more info.

Once these are set you can run the app, database, and database admin page with:

docker-compose up

For those running Linux, a convenience script run-services.sh is provided to simplify this and save some typing. You can edit the environment variables at the top of the script, and bring everything up with:

./scripts/run-services.sh

Run just the app

To run the app on it's own you can use Node.js. Ensure this is installed before continuing.

Install dependencies:

npm install

Run the app:

npm start

Note: You will need to manually set the environment variables before running this.

Run the tests:

npm test

Note: The test suite uses a separate set of environment variables, which can be set in test_env.sh.

About

A back-end based on the RealWorld API spec using Typescript, PostgreSQL, Node, Express, and Docker.

Topics

Resources

License

Stars

Watchers

Forks

Languages