Node Api Base is a boilerplate project for JSON RESTful APIs. It's based on Node v10.3.0 and Typescript v3.0.3.
This template comes with:
- Schema
- Users table with roles (Admin and Regular by default)
- Endpoints
- Sign up regular user
- Sign up admin user with authentication and authorization
- Authentication for both kinds of users
- Middleware
- Authentication
- Authorization (based on roles)
- Exception handling
- Tests
- Unit tests for user
- Integration tests for API
- Code quality tools
- API documentation following https://apiblueprint.org/
- Clone this repo
- Rename the folder and change
name
inpackage.json
to the project name - Create an
.env
file - In the
.env
file set the following values:If you want to use another database instead of using postgres you'll need to change theJWT_KEY = secret -> a secret value for json web token hashing DATABASE_URL = database url with format postgres://user:secret@host:port/database_name
app.ts
database connection method and also set the database url to an accordingly format - Run
yarn
- Run
yarn run dev
to run on development - You can now try your REST services!
Note: when creating an entity it must be exported in models/index.ts
in order to be used.
Tests: To run the tests after step 5, run yarn run test
(make sure to point to a test database on DATABASE_URL
)
- Run heroku create appName on the repo
- Add Heroku Postgres add-on (or whatever database you're using)
- Set environment values in heroku settings, as shown in the previous section (
DATABASE_URL
is probably already set) - Run
git push heroku branch
(whatever branch you want to push)
- body-parser Node.js body parsing middleware
- class-validator Validate incoming data
- dotenv Loads environment variables from a
.env
file toprocess.env
- express Fast, unopinionated, minimalist web framework for NodeJS
- lodash The Lodash library exported as Node.js modules
- pg Non-blocking PostgreSQL client for NodeJS
- pug High performance template engine
- reflect-metadata Runtime reflection on types
- typeorm ORM that can run in NodeJS
- ts-node TypeScript execution and REPL for NodeJS
- tslint Extensible static analysis tool for TypeScript
- typescript Language for application-scale JavaScript
- bcrypt Lib to help to hash passwords
- express-async-errors Simple ES6 async/await support hack for ExpressJS
- winston A logger for just about everything
- jsonwebtoken An implementation of JSON Web Tokens
- jest Delightful JavaScript Testing
- ts-jest TypeScript preprocessor with source map support for Jest
- supertest HTTP assertions made easy via superagent
- tslint-eslint-rules TypeScript rules available in ESLint
https://nodeapibase.docs.apiary.io
v1.0.0