NodeJS API built for 0x Tracker which exposes 0x protocol data and metrics for consumption by the 0x Tracker Client application.
- Requirements
- Getting Started
- Tech Stack
- Project Structure
- NPM Scripts
- Nodemon
- Continuous Integration
- Maintainers
- License
Node.js is required to run the server application. A .nvmrc
file is provided for the convenience of using NVM.
You'll need a MongoDB database populated with data from the 0x Tracker Worker process. For the time being this will need to be done by running the 0x Tracker Worker against your database. In the future the goal is to have a subset of data available as backups for getting up and running quickly.
It's recommended that you use Prettier and ESLint editor plugins if contributing to the project. Pre-commit hooks are in place which will prevent code which doesn't conform to Prettier/ESLint rules from being committed.
Assuming you have all the pre-requisites, getting started is pretty simple:
$ npm i
$ cp .env.example .env
$ npm start
If you're not running MongoDB on the default local port then jump into your projects .env
file and modify the connection string before running npm start
.
If you plan to contribute to the project then its worthwhile familiarising yourself with the following tools which constitute the bulk of the tech stack.
- Koa - Node.js web framework which handles API routing and response building.
- Mongoose - MongoDB ORM providing simple and secure access to the database.
- Node-config - Handles application level configuration through config files and environment variables.
- 0x.js - Official 0x Protocol helper library for manipulating 0x fill data.
- Axios - Lightweight HTTP client used for fetching API data.
- Lodash - Powerful general purpose utility belt for writing clean code.
- Moment.js - Begrudgingly used as a fallback when manipulating UTC dates whilst awaiting UTC support in date-fns.
- Jest - All-in-one Javascript testing framework which executes unit & integration tests.
- ESLint - Provides linting for Javascript code ensuring common code quality issues are surfaced and preferred coding conventions are automated.
- Prettier - An opinionated code formatter which ensures consistent formatting across the codebase.
- husky - Ensures git pre-commit hooks are in place to enforce ESLint & Prettier rules.
- lint-staged - Speeds up pre-commit hooks by ensuring only the modified files are linted.
- Renovate - Helps keep dependencies up to date by monitoring for updates and automatically opening pull requests.
The project structure is designed to minimize the number of directories, increase discoverability and ensure related code is grouped together. Feature code is grouped based on what "feels right" and is subject to refactoring over time.
If a convention exists for locating configuration files related to developer tooling then it should be followed (e.g. .babelrc
or .eslintrc.js
).
- config - Tooling configuration which doesn't have a conventional location.
- src - Application specific code and test files.
- app - Koa application files.
- middleware - Custom Koa middleware.
- routes - Koa routers.
- util - Utilities used by Koa application files.
- config - Application configuration files used by Node-config.
- [feature] - Business logic and helpers related to a specific feature.
- ...
- model - Mongoose document models.
- util - All other helper functions used to support the codebase.
- constants.js - Shared constants. Each constant should be a named export.
- index.js - Application entry point.
- app - Koa application files.
A number of NPM scripts are provided for automating common tasks.
- lint - Lint all code files in the project.
- start - Start the API server.
- test - Run unit/integration tests and produce coverage report.
- test:watch - Run unit/integration tests in watch mode.
The recommended way of developing locally with 0x-tracker-api is to use Nodemon. The project has a Nodemon configuration file which ensures the application will restart whenever relevant files are changed.
To get started with Nodemon:
$ npm i -g nodemon
$ nodemon
Continuous integration for the project is handled by Travis CI which runs linting, tests, and builds the sources for every pull request. Merged pull requests are automatically deployed to production.
- Craig Bovis (@cbovis)
Infrastructure for 0x Tracker is generously supported by these companies.
Bugsnag |
CryptoCompare |
Netlify |