Build Simple Nodejs API for Microservice

Yoweni
3 min readMay 26, 2021

--

In this article we are gonna build Nodejs project for API and next we will integrate services with a gateway, so that is microservice.

This project we will build user service that focus for user management such as login, register and detail user. Steps to build user service are:
- Create Express project
- Install Sequelize
- Create migration
- Create seeder with fake data
- Modify Config
- Modify model
- Create API
- Register to routes
- Run in Postman

https://saac.instructure.com/eportfolios/6856/Home/VerCruella_Pelcula_en_Lnea_HD2021_Completa_En_Espaol_Latio
https://kenny.instructure.com/eportfolios/4494/Home/Ver_Cruella_2021_HD_en_Lnea_pelcula_completa
https://mitchellschools.instructure.com/courses/7426/pages/cruella-2021-cruella-pelicula-cruella-pelicula-sub-espanol-cruella-pelicula-completa-~-2021-%7Cver-cruella-peliculas-en-espanol-online-gratis-2021-cruella-la-pelicula-completa-en-espanol-y-subtitulado-latino-hd-sub-espanol
https://saac.instructure.com/eportfolios/6904/Home/720p_Patrulla_trueno_2021_Pelicula_Completa_Espaol_y_Latino
https://kenny.instructure.com/courses/185/pages/ver-patrulla-trueno-2021-%7C-pelicula-completa-%7C-con-espanol-y-latino
https://saac.instructure.com/eportfolios/6966/Home/VerGratis__Despierta_la_furia_2021__Pelcula_Completa_HD__DVdrip
https://kenny.instructure.com/eportfolios/4523/Home/VerDESPIERTA_LA_FURIA_Pelcula_en_Lnea_HD2021_Completa_En_Espaol_Latio
https://mitchellschools.instructure.com/courses/7432/pages/despierta-la-furia-2021-despierta-la-furia-pelicula-despierta-la-furia-pelicula-sub-espanol-despierta-la-furia-pelicula-completa-~-2021-%7Cver-despierta-la-furia-peliculas-en-espanol-online-gratis-2021-despierta-la-furia-la-pelicula-completa-en-espa
https://saac.instructure.com/eportfolios/7003/Home/720p_DESPIERTA_LA_FURIA_2021_Pelicula_Completa_Espaol_y_Latino
https://kenny.instructure.com/courses/186/pages/ver-despierta-la-furia-2021-%7C-pelicula-completa-%7C-con-espanol-y-latino

Create Express Project

For create a project, you need install Nodejs and Express in your PC. Then, you can use this command

Install Sequelize

Sequelize is a library that make our Nodejs project can using database. It features solid transaction support, relations, eager and lazy loading, read replication and more. You can read more the documentation here. For using Sequelize, you need to install sequelize and sequelize-cli (optional). But i recommend you to install sequelize-cli.Create Migration

To create migration file, you can use Sequelize CLI. Now we create a migration file for users table with name create_table_users. You can follow this commandInside create_table_users file, we define the fields of users table.

Create Seeder with Fake Data

Seeder is way to let us insert the initial data to our database, for generate dummy data its called Faker Factory. Next we create a seeder file with name user-seeders.Inside the file, we will insert dummy data for users table using faker. Because we have password field that need to be encrypted, so we also need bcryptjs for encryption. Here is the user-seeders file.Modify Config

To connect our Nodejs with database, we need some configuration in config file. How i config the configuration file are:
- Install dotenv
- Create an .env file, fill the file with PORT, DB_HOST, DB_NAME, DB_USERNAME, DB_PASSWORD variables.
- import dotenv in app.js
- rename config.json to config.js
- convert json code into js codeModify Models

As default, User Model created already when we install Sequelize into our Nodejs project, so we only need to adjust the field as we declare in migration file.Create API

For me, foldering is an important thing. With good folder management its help us to easy to maintain and scale up as well. Here is how i set the folders.

https://www.guest-articles.com/health/the-end-is-near-no-seriously-26-05-2021
https://www.guest-articles.com/web-design/breaking-the-trance-how-i-escaped-ideos-biased-career-labyrinth-26-05-2021
https://dreampirates.us/world/breaking-the-trance-how-i-escaped-ideos-biased-career-labyrinth-26-05-2021
https://dreampirates.us/technology/after-booting-ubuntu-on-the-pi4-26-05-2021
https://alfacleaner.com/technology/after-booting-ubuntu-on-the-pi4-26-05-2021
https://alfacleaner.com/general/breaking-the-trance-how-i-escaped-ideos-biased-career-labyrinth-26-05-2021
https://www.thewyco.com/news/breaking-the-trance-how-i-escaped-ideos-biased-career-labyrinth-26-05-2021
https://www.thewyco.com/business/top-interview-questions-on-node-js-development-you-must-know-about-in-2021-26-05-2021
https://steemkr.com/techdesign/@ashubhamp/breaking-the-trance-how-i-escaped-ideo-s-biased-career-labyrinth
https://gumroad.com/angelaluis
https://muckrack.com/pirintil-mamprang/bio
https://cox.tribe.so/post/https-saac-instructure-com-eportfolios-6856-home-vercruella-pelcula-en-lnea--60aea2078c77821c9d70e6df
https://myanimelist.net/blog.php?eid=862094
https://paiza.io/projects/5cOLZJYurnoXavXWtgIHEg
https://onlinegdb.com/JdguE1fY7
https://jsfiddle.net/getamovie/ejsd0qy3/
https://www.peeranswer.com/question/60aea327019ef3b819088a60
https://dumpz.org/ageg4aGgD8xa
http://paste.jp/5c7b6a13/
https://rentry.co/z6pf8
https://healthymboa.org/forum-healthymboa/topic/us-urges-transparent-who-inquiry-into-covid-origins/#postid-4808
https://www.atoallinks.com/2021/top-interview-questions-on-node-js-development-you-must-know-about-in-2021/

--

--