Everyone needs an API these days, right?
- Node.js 9+
- MySQL
- Express web framework
- Knex SQL query builder
- Ava for concurrent tests
- Babel JS transpiler
- Joi schema validator
- JWT for stateless authentication
Folders look like this:
.
├── src
│ ├── api # API modules (i.g. user, auth, etc.)
│ ├── db # Database connection module
│ ├── job # Recurring jobs
│ ├── middleware # Express middlewares
│ ├── migration # Database migrations
│ ├── model # Application model classes
│ ├── seed # Database seeds
│ ├── schema # Schemas
│ ├── script # Script files (sql, bash, etc.)
│ ├── util # Resuable modules
│ └── index.js # Application entry file
└── test # Test files
Note: some files were omitted for simplicity.
- Clone the repo:
git clone https://github.com/ruanmartinelli/api-starter.git <NEW_NAME>
cd <NEW_NAME>
# make it yours:
rm -rf .git
git init
- Install dependencies
yarn install
- Create a .env file (remember to add your keys)
mv .env.example .env
- Run migrations:
npm run db:latest
Note: this assumes you have MySQL installed
- Run
npm run dev
Start the server in Production mode:
npm start
Start the server in Development mode:
npm run dev
Show lint errors:
npm run lint
Show lint errors and fix minor issues:
npm run lint:fix
Run AVA tests:
npm t
Run AVA tests in watch mode:
npm run test:watch
Generate API documentation:
npm run docs
- Folder and file names are always on singular (eg.
user.js
,script/
) function x() { }
instead ofconst x = () => {}
- All Standard rules
MIT © Ruan Martinelli