npm install generator-koa-api> Yeoman generator
Not every new computer comes with a Yeoman pre-installed. He lives in the npm package repository. You only have to ask for him once, then he packs up and moves into your hard drive. Make sure you clean up, he likes new and shiny things.
``bash`
npm install -g yo
Yeoman travels light. He didn't pack any generators when he moved in. You can think of a generator like a plug-in. You get to choose what type of application you wish to create, such as a Backbone application or even a Chrome extension.
To install generator-koa-api from npm, run:
`bash`
npm install -g generator-koa-api
Finally, initiate the generators:
`bash`
yo koa-api your-api # Initialize project
yo koa-api:api /tasks # Generate router and test files
yo koa-api:api /tasks/results # Nested routers!
yo koa-api:model task # Generate model for sequelize
After edit your configuration in config/, run:
`bash`
npm test # Run tests for APIs
npm start # Start server
6 steps to contribute:
`cd1. Fork and clone this repo and
to the repobin2. Link your
s`
npm link3. Setup database for test
mysql -e 'create database database_test;'4. Edit code and test
5. Run tests
npm test6. Create pull request for your changes
- After running npm start, you can find your service's PID by run pgrep
your-api because your starter file was named by name field in yourpackage.json
.debug
- Use for logging, so you can switch logs with DEBUG environmentDEBUG
variable value.
- All generated routers have setted channel for with path (e.g.,SQLs
your-api:api:/users).
- Print by setting DEBUG=your-api:modelsmodels/
- Table names for models are named by filenames in .bin/sync-models.js
- Use to create tables for models.this.app.models
- You can use your models in your router with .lib/loaders/
- Put your service clients/loaders into , so your can manage themapi/` can be copy/move to anywhere with the same structure and run without any code.
with best practice.
- Folders in
Yeoman has a heart of gold. He's a person with feelings and opinions, but he's very easy to work with. If you think he's too opinionated, he can be easily convinced.
If you'd like to get to know Yeoman better and meet some of his friends, Grunt and Bower, check out the complete Getting Started Guide.
MIT