mu-koan-generator
v1.1.0
Published
A Koa scaffolding generator for JSON REST APIs
Downloads
4
Maintainers
Readme
mu-kōän-generator 公案-ジェネレータ
Installation
$ npm i -g mu-koan-generator
Usage
To get started with a Koa 2.0.0+ REST JSON API use the command line executable mu-koan(1)
to generate an application as shown:
- Create the application:
$ mkdir my-awesome-api && cd my-awesome-api
$ mu-koan
info: [mu-koan] Creating project "my-awesome-api" into [/home/you/dev/my-awesome-api]
info: [mu-koan] Created /home/you/dev/my-awesome-api
info: [mu-koan] Created /home/you/dev/my-awesome-api/.editorconfig
info: [mu-koan] Created /home/you/dev/my-awesome-api/.eslintrc
info: [mu-koan] Created /home/you/dev/my-awesome-api/.gitignore
info: [mu-koan] Created /home/you/dev/my-awesome-api/app
info: [mu-koan] Created /home/you/dev/my-awesome-api/app.js
info: [mu-koan] Created /home/you/dev/my-awesome-api/app/config
info: [mu-koan] Created /home/you/dev/my-awesome-api/app/config/index.js
info: [mu-koan] Created /home/you/dev/my-awesome-api/app/config/properties.json
info: [mu-koan] Created /home/you/dev/my-awesome-api/app/logger.js
info: [mu-koan] Created /home/you/dev/my-awesome-api/app/routes
info: [mu-koan] Created /home/you/dev/my-awesome-api/app/routes/status.js
info: [mu-koan] Created /home/you/dev/my-awesome-api/app/server.js
info: [mu-koan] Created /home/you/dev/my-awesome-api/build.json
info: [mu-koan] Created /home/you/dev/my-awesome-api/gulpfile.js
This will run npm init
and npm install
after generating the initial scaffolding.
- Fire it up:
$ npm start
[12:59:48] Using gulpfile ~/dev/js/my-awesome-api/gulpfile.js
[12:59:48] Starting 'default'...
[12:59:48] Starting 'eslint'...
[12:59:49] Finished 'eslint' after 736 ms
[12:59:49] Starting 'nodemon'...
...
2016-07-22 12:59:49,648 - info: [my-awesome-api] Starting and configuring Koa server
2016-07-22 12:59:49,662 - info: [my-awesome-api] Configuring routes for [/api/status]
2016-07-22 12:59:49,671 - info: [my-awesome-api] ✔ Koa server listening on 127.0.0.1:3000 [development]
- Check everything's working as expected by requesting
/api/status
. In a new terminal session, run:
$ curl http://localhost:3000/api/status
{
"success": true,
"name": "my-awesome-api",
"version": "1.0.0-dev",
"timestamp": "Jul 19, 2016 4:31 PM",
"process": {
"platform": "linux",
"pid": 24238,
"mem": {
"rss": 49418240,
"heapTotal": 34317856,
"heapUsed": 23951544
}
}
You can change or remove the
/api
namespace by modifying"koa.routes.prefix"
option onapp/config/properties.json
or by starting the API withnpm start -- --koa.routes.prefix foo
.
Command line interface
Usage: mu-koan [-f --force] [-v]
Options:
-h, --help Show help [boolean]
-v, --verbose Sets the verbosity level for log messages [count]
-V, --version Show version number [boolean]
--name [default: (generated-value)]
https://github.com/nfantone/mu-koan-generator
https://github.com/nfantone/mu-koan-generator
Features
Along with a working webserver, the generator creates some common files that feature additional functionality or help you follow standard practices, such as:
- A gulpfile.js with some common tasks like
gulp eslint
for linting orgulp nodemon
to start a nodemon process. - Linting rules based on xo-space and semistandard ESLINT configurations.
- An
.editorconfig
file. - A
.gitignore
with many common entries (thanks to https://gitignore.io). - Includes mu-kōän as a dependency, so you get many helpful Koa middlewares out-of-the-box.
- Includes mu-kōän-router as a dependency for automatic controller discovery: just drop a
.js
file under/routes
. - A readily configured
winston
logger atapp/logger.js
. - A
routes/status.js
controller that prints out simple information on the running process onGET /api/status
. - Stores its configuration on an
nconf
instance, supporting command line arguments, environment variables and aconfig/properties.json
file as sources.
License
MIT