Read more about Babel from here.
git clone https://github.com/alextanhongpin/node-rest.git
git remote rm origin
git remote add origin <your-git-path>
The architecture is based on the principle of Dependency Inversion. There are layers wrapping around each circle, forming the famous onion. Between the layers of the Onion, there is a strong dependency rule: outer layers can depend on lower layers, but no code in the lower layer can depend directly on any code in the outer layer.
Note that the database is not center, it is external. The moment you grasped this concept, you have grasped the onion architecture.
Here you can specify the version of nodejs that you want the code to compile to. Since we are using AWS Lambda, we want the code to compile to nodejs version 6.10
(7 November 2017). If you are not bounded by this limitation, always use the current version:
{
"presets": [
["env", {
"targets": {
"node": "current"
}
}]
]
}
First, you have to install Yarn. Then:
# This will install all dependencies from package.json
$ yarn install
# We use foreman to load the environment variables from `.env` file.
# This is important to prevent accidental commit of sensitive data to github
$ yarn global add foreman
$ yarn add <PACKAGE_NAME>
$ yarn add --dev <PACKAGE_NAME>
$ yarn remove <PACKAGE_NAME>
For development, store all the environment variable in the .env
file. This will be included in .gitignore
so that it will not be commited to github.
Make sure you create the .env
file or the service will not run.
The .env
should contain the following:
DB_USER=user
DB_PASS=123456
DB_NAME=testdb
DB_HOST=localhost
FOOD_SERVICE=true
Any running MySQL will prevent the app from connecting to the docker container.
If you don't stop the MySQL, the following error might appear:
$ error 1044 (42000): access denied for user
$ docker-compose up -d
$ nf start
You can use any reporters that are supported by istanbul: clover
, cobertura
, html
, json-summary
, json
, lcov
, lcovonly
, none
, teamcity
, text-lcov
, text-summary
, text
.
$ yarn test
$ yarn cover
$ yarn build
$ docker exec -it $(docker ps -f name=database -q) mysql -u user -p
Enter password: 123456
CREATE TABLE food (
id int NOT NULL,
name varchar(255) NOT NULL,
PRIMARY KEY (ID)
);
Build a production release first:
$ yarn build
Enable profiling:
NODE_ENV=production node --prof app.js
Put some load on the server using ab
(Apache Bench):
$ ab -k -c 20 -n 250 "http://localhost:5000/foods"
Process:
$ node --prof-process isolate-0x103800000-v8.log > processed.txt