node-api-base
                                
                                 node-api-base copied to clipboard
                                
                                    node-api-base copied to clipboard
                            
                            
                            
                        API boilerplate project for NodeJS with Typescript
Node API Base
Node Api Base is a boilerplate project for JSON RESTful APIs. It's based on Node v10.3.0 and Typescript v3.0.3.
Features
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/
How to use
- Clone this repo
- Rename the folder and change nameinpackage.jsonto the project name
- Create an .envfile
- In the .envfile 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_nameapp.tsdatabase connection method and also set the database url to an accordingly format
- Run yarn
- Run yarn run devto 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)
Deploying to Heroku
- 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_URLis probably already set)
- Run git push heroku branch(whatever branch you want to push)
NPM Packages
- body-parser Node.js body parsing middleware
- class-validator Validate incoming data
- dotenv Loads environment variables from a .envfile 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
Api Docs
https://nodeapibase.docs.apiary.io
Current version
v1.0.0