An open API service indexing awesome lists of open source software.

https://github.com/erhant/expressjs-web3-starter

An ExpressJS starter repository for Web3.0, with TypeScript.
https://github.com/erhant/expressjs-web3-starter

backend ethers expressjs node prisma redis web3

Last synced: 3 months ago
JSON representation

An ExpressJS starter repository for Web3.0, with TypeScript.

Awesome Lists containing this project

README

          

# ExpressJS Web3.0 Starter

A generic backend with Redis, Prisma ORM (to PgSQL) and Ethers setup. It also has a signature-based authorization middleware, that maps a common signature to a public key.

## Setup

You need to have the following:

- A Redis server running
- A PostgreSQL server running
- A gRPC URL and ChainID

The connection information for these are stored in `.env`. See an example file under [environments](./environments/.env.local).

## Usage

Just run `yarn` to install the packages and then `yarn run start` to start the server. An environment file `.env` is required as follows:

```bash
PORT=
```

## Testing

Start the backend in a terminal with `yarn run start:test`, and in another run `yarn test` to execute unit tests. You can skip some tests with `.skip` if wanted, as linter will not be happy with the code when you comment stuff out. Note that Jest also sets `NODE_ENV` variable to be `test` when during testing.

## Structure

The entry point is [`app.ts`](./src/app.ts). The other files are structured as follows:

- [clients](./src/clients/): API setups and accessors.
- [config](./src/configurations/): configurations, mostly overwritten by environment variables.
- [constants](./src/constants/): non-configuration constants, whether it is a string literal used around or some parameter.
- [controllers](./src/controllers/): final entry-points for each endpoint. We expect the responses to be made from within this file.
- [interfaces](./src/interfaces/): custom TypeScript interfaces.
- [middlewares](./src/middlewares/): Express middlewares, such as validation.
- [routes](./src/routes/): Express routes, which define the endpoint URLs.
- [tests](./src/tests/): Jest unit-test files.
- [utilities](./src/utilities/): general utility files.
- [validators](./src/validators/): Joi validator schemes for endpoints. Note that we can have non-endpoint schemas here too, which are used to build up the endpoint schemas.

Within the [tests](./src/tests/) folder, there are also utilities, mock data and isolated scripts.

## Code Style

[![Code Style: Google](https://img.shields.io/badge/code%20style-google-blueviolet.svg)](https://github.com/google/gts)

[Google TypeScript](https://github.com/google/gts) code formatting & linting is used as an extension of `eslint` and `prettier`. I have also included my VSCode settings, though you should feel free to change them.