Skip to content

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

License

Notifications You must be signed in to change notification settings

erhant/expressjs-web3-starter

Repository files navigation

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.

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:

PORT=<the port to listen>

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. The other files are structured as follows:

  • clients: API setups and accessors.
  • config: configurations, mostly overwritten by environment variables.
  • constants: non-configuration constants, whether it is a string literal used around or some parameter.
  • controllers: final entry-points for each endpoint. We expect the responses to be made from within this file.
  • interfaces: custom TypeScript interfaces.
  • middlewares: Express middlewares, such as validation.
  • routes: Express routes, which define the endpoint URLs.
  • tests: Jest unit-test files.
  • utilities: general utility files.
  • 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 folder, there are also utilities, mock data and isolated scripts.

Code Style

Code Style: Google

Google TypeScript 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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published