Simple Micro-service with NodeJS
Step by step to create environment for application execution. The instructions below are for Linux OS.
- Install Docker
- Prepare Containers
- Execute Application
- Helio Nogueira
For install Docker, follow the instructions in Docker.
Instructions for preparing application containers.
$ mkdir -p "${HOME}/workspace"
$ cd "${HOME}/workspace"
$ git clone "https://github.com/helionogueir/simple-microservice-nodejs.git"
$ cd "${HOME}/workspace/simple-microservice-nodejs"
$ cp "config.example.json" "config.json"
Follow the instructions below.
$ docker run \
--name "simple-microservice-nodejs-database" \
--env "MYSQL_ROOT_PASSWORD=root" \
--detach "mysql:5.7"
Follow the instructions below.
$ docker exec -it "simple-microservice-nodejs-database" /bin/bash
$ mysql -uroot -proot
If you're seeing "mysql>" in your display, means you're connected. Now follow the instructions below.
mysql> CREATE SCHEMA `simple-microservice-nodejs` DEFAULT CHARACTER SET utf8;
mysql> USE `simple-microservice-nodejs`;
mysql> CREATE TABLE IF NOT EXISTS `users` (
`id` bigint(18) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`age` int(3) NOT NULL,
`created` datetime DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
mysql> INSERT INTO `users` (`name`, `age`) VALUES ('August Maynard', '18');
INSERT INTO `users` (`name`, `age`) VALUES ('Owais Gibson', '57');
INSERT INTO `users` (`name`, `age`) VALUES ('Shay Tillman', '38');
INSERT INTO `users` (`name`, `age`) VALUES ('Ryley Klein', '11');
INSERT INTO `users` (`name`, `age`) VALUES ('Vinay Dunne', '12');
INSERT INTO `users` (`name`, `age`) VALUES ('Esme Wagstaff', '15');
INSERT INTO `users` (`name`, `age`) VALUES ('Skylar Olsen', '98');
INSERT INTO `users` (`name`, `age`) VALUES ('Manuel Butler', '112');
INSERT INTO `users` (`name`, `age`) VALUES ('Kamron Lam', '1');
INSERT INTO `users` (`name`, `age`) VALUES ('Buddy Gilmore', '33');
mysql> SELECT * FROM `users`;
Follow the instructions below.
$ docker run \
--name "simple-microservice-nodejs-application" \
--volume "${HOME}/workspace/simple-microservice-nodejs":/var/www/application \
--link "simple-microservice-nodejs-database" \
--tty --interactive node:8.10 /bin/bash
Here you will prepare and execute the application. Follow the instructions below. You need connected on container "simple-microservice-nodejs-application".
$ cd "/var/www/application"
$ npm install
$ npm start