Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/trufa-me/node-es6-api-framework
Node ES6 API Framework
https://github.com/trufa-me/node-es6-api-framework
api api-framework babel babeljs boilerplate boilerplate-api coverage-report docker es6-javascript express husky nodejs nodemon nvm prettier yarn
Last synced: about 1 month ago
JSON representation
Node ES6 API Framework
- Host: GitHub
- URL: https://github.com/trufa-me/node-es6-api-framework
- Owner: Trufa-me
- Archived: true
- Created: 2017-04-26T13:58:06.000Z (over 7 years ago)
- Default Branch: release/continuous
- Last Pushed: 2018-06-09T08:30:22.000Z (over 6 years ago)
- Last Synced: 2024-09-28T06:21:59.160Z (about 1 month ago)
- Topics: api, api-framework, babel, babeljs, boilerplate, boilerplate-api, coverage-report, docker, es6-javascript, express, husky, nodejs, nodemon, nvm, prettier, yarn
- Language: JavaScript
- Size: 257 KB
- Stars: 4
- Watchers: 7
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Boilerplate API
This boilerplate is responsible for being the base from which to start creating an API.
This project is using babel to transpile back to ES5 on server! YAY! For performance reasons it is advisable not to run babel-node in production.
Its is therefore extremely important to pre-compile the project and run the compiled version instead. This is what the command npm run build
is used for.Ways to run the app are outlined later in this readme file.
Current endpoints:
POST /v1/someapi/example
POST /v1/someapi/example### Version
1.0.0### Tech
This API uses a number of open source projects to work properly:
* [babeljs] - Use next generation JavaScript, today! Transforms code back to ES5!
* [docker] - Ensure environment is configured the same anywhere it is deployed.
* [node.js] - evented I/O for the backend
* [Express] - fast node.js network app framework [@tjholowaychuk]And of course this boilerplate can be seen here [public repository][git-repo-url]
on Stash.### Installation
Boilerplate API requires [Node.js](https://nodejs.org/) v6+ to run.
Open your favorite Terminal and run these commands.
```sh
$ git [email protected]:Trufa-me/Node-ES6-API-Framework.git
$ cd Node-ES6-API-Framework
```You can move confg/example_default.js to more convenient place e.g. /etc/jobsite/Node-ES6-API-Framework/default.json and point confg/example_default.js symlink to a new target.
In your terminal, run the following as below:
```sh
$ ln -s /etc/jobsite/Node-ES6-API-Framework/default.json config/default.json
```### Start application for Development
Open your favorite Terminal and run these commands.
In development project relies on nvm as well as yarn so install those:
Install nvm:
```sh
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
nvm install v8.9.0```
Install yarn:
```sh
$ npm install -g yarn
```Run the following:
```sh
$ ./bin/start.sh
```This command should start api in development mode with [nodemon] and restart api every time you save a file.
### Production - this is for running production locally (Docker handles building the compiled version)
Open your favorite Terminal and run these commands.
Run the following:
```sh
$ ./bin/start.sh build
$ ./bin/start.sh start:prod
```You should get below output:
```[developer@myMachine Node-ES6-API-Framework]$ ./bin/start.sh
Found '/home/developer/projects/Node-ES6-API-Framework/.nvmrc' with version
Now using node v6.10.0 (npm v4.1.2)
yarn install v0.20.3
warning [email protected]: "dependencies" has dependency "nodemon" with range "^1.11.0" that collides with a dependency in "devDependencies" of the same name with version "^1.9.0"
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.64s.> [email protected] start:dev /home/developer/projects/Node-ES6-API-Framework
> cross-env NODE_ENV=development ./node_modules/nodemon/bin/nodemon.js nodemon[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: /home/developer/projects/Node-ES6-API-Framework/src/**/*
[nodemon] starting `npm run babel-node -- src/index.js nodemon`> [email protected] babel-node /home/developer/projects/Node-ES6-API-Framework
> babel-node --ignore node_modules,tests "src/index.js" "nodemon"Front-End server is running at http://localhost:40001
Try me: http://localhost:40001/v1/someapi/promise
```### Tests
Open your favorite Terminal and run these commands.
Run the following:
```sh
$ ./bin/start.sh test
```Output:
```[developer@myMachine Node-ES6-API-Framework]$ ./bin/start.sh test> [email protected] test /home/developer/projects/Node-ES6-API-Framework
> mocha --recursive ./tests/ --compilers js:babel-core/registerboilerplate api configuration
✓ should contain all the correct configuration options1 passing (58ms)
[developer@myMachine Node-ES6-API-Framework]$
```### Generate test coverage report
Run the following:
```sh
$ ./bin/start.sh test:coverage
```Output:
```[developer@myMachine Node-ES6-API-Framework]$ ./bin/start.sh test:coverage> [email protected] test:coverage /home/developer/projects/Node-ES6-API-Framework
> nyc --reporter=lcov --reporter=text ./node_modules/.bin/mocha --recursive --require babel-register ./tests/boilerplate api configuration
✓ should contain all the correct configuration options1 passing (11ms)
----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files | Unknown | Unknown | Unknown | Unknown | |
----------|----------|----------|----------|----------|----------------|
[developer@myMachine Node-ES6-API-Framework]$
```Viewing the coverage report:
Open explorer and navigate to your project dir and open coverage/lcov-report/index.html
### Docker
API Framework is very easy to install and deploy as a Docker container.```sh
cd boiler-plate-api
docker build .
```This will create the Boilerplate API image and pull in the necessary dependencies. Once done, run the Docker and map the port to whatever you wish on your host 40001 in this case:
```sh
docker run -d -t -p 40001:40001 --name boiler_plate_api --restart=always boiler_plate_api
```Verify the deployment by navigating to your server address in your preferred browser.
e.g http://localhost:40001/v1/someapi/example
[//]: # (These are reference links used in the body of this note and get stripped out when the markdown processor does its job. There is no need to format nicely because it shouldn't be seen. Thanks SO - http://stackoverflow.com/questions/4823468/store-comments-in-markdown-syntax)
[babeljs]:
[docker]:
[git-repo-url]:
[git-clone-url]:
[node.js]:
[express]:
[nodemon]:## Node.JS Debugging
### Local debugging
First you need to run process that will be continuously transpile your code:```sh
$ npm run compile
```With transpile running you can use Visual Studio Code -> Debugging
And run **Launch App.js** launch settings.
### Remote debugging
1) Run process that will be continuous transpile your code:```sh
$ npm run compile
```2) Start application in debug mode listening on a desired:
```sh
node_modules/nodemon/bin/nodemon.js --config nodemon-debug.json
```3) Having both commands running on remote machine
Visual Studio Code -> DebuggingMake sure **host** and **remoteRoot** are pointing to correct locations.
And run **Launch Remote Ap** launch settings.
Unfortunately in this mode breakpoints cannot be set correctly from VSCode and instead you need to add:
``` javascript
debugger;
```In place where you want debugger to stop. From there you can step over as usual in any IDE having preview on any local variables and references.