A service to manage the users.
Read this file preview mode. Open this file and press Ctrl+shift+v
to view in preview mode in VS code. And if you find this document is old and needs to be updated, please update this document don't just ingore it.
-
Run
npm run setup
to install depedencies. -
Run
npm run build
to transpile ts files to js files. -
Run
npm start
to start service.
-
All the steps and commands mentioned in this documetation are tested in ubuntu 18.04.5LTS, below mentioned steps may not work as expected in other platforms like windows or other distribution of linux.
-
This service runs on node.js and requires npm to manage the packages, at the time of creating this documentation this service runs on node.js verion 10.24.1 and requires npm 6.14.12. Make sure specified version of node.js and npm is installed in our machine.
-
This service uses mysql as primary database, make sure mysql is installed and running on port 3306.
-
create database with the name
user_service
.
-
Installing node_modules, run below command to install node_modules
$ npm run setup
Above command is a npm script which installs the node_modules. If you don't know how npm scripts works, we highly recommand you to go through this link and understand npm scripts before running the command.
-
After installing node_modules we need to transpile TypeScript files to JavaScript files. If you don't know why we need to transpile TypeScript files to JavaScript files, find the documetation in this link and understand why we need to transpile TypeScript files to JavaScipt files. Once you understood, run the following command below commad to transpile TypeScript files.
$ npm run build
-
We assume that you have completed steps mentioned Prerequisite, Setup Code, otherwise there will be issues in starting the service.
-
To start main run below command
$ npm start
-
We can also start service using pm2. If you don't know what is pm2, read about pm2 in this link.
-
To start service using pm2 run below command.
$ bash bin/start-server.sh
-
You can check the logs, restart, stop and delete the services using pm2 commands, check the commands in link mentioned in step 3.
-
To start using nodemon, run below commad.
$ npm run start:nodemon:ts
The folder structure of this app is explained below:
Name | Description |
---|---|
.vscode | Contains debug files |
node_modules | Contains all npm dependencies |
bin/ | Contains files to start and stop the service |
dist/ | Contains transpiled code which can run |
src/ | Contains source code |
src/config | Contains config files |
src/db | Contains db related code |
src/routes | Contains code related APIs exposed by this service |
src/Server.ts | Starting point to this service |
package.json | Contains npm dependencies as well as |
Dockerfile | File to build the docker image |
tsconfig.json | Config settings for compiling source code only written in TypeScript |
tslint.json | Config settings for TSLint code style checking |
Method | URI | |
---|---|---|
POST | /internal/api/v1/users | create a user |
GET | /internal/api/v1/users/:id | returns user details by emailid |
GET | /internal/api/v1/users | returns all the users |
PUT | /internal/api/v1/users/:id | updates the user by emailid |
DELETE | /internal/api/v1/users/:id | delete the user by emialid |
POST | /api/v1/auth/login | returns jwt token |