- Node.js
- Express
- Typescript
- MySQL
- TypeOrm
This API Service can be run in Node.js and MySQL environments
Use either following command to clone the repository
git clone git@github.com:lakeedrock/user_login_api.git
or
git clone https://github.com/lakeedrock/user_login_api.git
Run following commands in your terminal to generate config files
.env
and ormconfig.json
// Change path to project directory
cd user_login_api
// Create config files
cp sample.env .env
cp sample.ormconfig.json ormconfig.json
using your favourite text editor update following config values
PORT= { Application server port }
SECRET_KEY= { JWT secret key }
MAX_AGE= { Lifetime of JWT cookie : 86400000 (one day) }
FRONTEND_ORIGIN= { Origin for cors : "http://localhost:80" }
{
"type": "", // Database type : mysql
"host": "", // Database host : localhost // mysql_server for docker
"port": "", // Database port : 3308
"username": "", // Database user : root
"password": "", // Database user password : Dev@r0ot
"database": "", // Database name: node_db
"entities": ["src/entity/*.ts"],
"logging": false, // Set to true if you need to see logs in console
"synchronize": true,
"dropSchema": true
}
run following command in terminal in your project root
docker compose up
- Node Js and NPM installed
- MySQL server installed
- Postman installed (For testing purposes)
npm install
npm run start
npm run build
npm run test
Use Postman
application to test the API service. Download Postman
application from https://www.postman.com/downloads/
Import API collection json file from postman/Node User API.postman_collection.json
to Postman. For more instruction please visit https://learning.postman.com/docs/getting-started/importing-and-exporting-data/
API Call : http://api_service_url/api/register
Method : POST
Body Parms Object:
{
"firstName": String,
"lastName": String,
"email": String,
"password": String,
"passwordConfirmation": String
}
Response Object:
{
"first_name": String,
"last_name": String",
"email": String,
"id": Number
}
API Call : http://api_service_url/api/login
Method : POST
Body Parms Object:
{
"email": String,
"password": String
}
Response Object:
{
"message": "success",
}
API Call : http://api_service_url/api/user
Method : GET
Body Parms Object: { none }
Response Object:
{
"id": Number,
"first_name": String,
"last_name": String,
"email": String
}
API Call : http://api_service_url/api/user
Method : PUT
Body Parms Object:
{
"firstName": String,
"lastName": String,
"email": String
}
Response Object:
{
"id": Number,
"first_name": String,
"last_name": String,
"email": String
}
API Call : http://api_service_url/api/password
Method : PUT
Body Parms Object:
{
"currentPassword": String,
"newPassword": String,
"passwordConfirmation": String
}
Response Object:
{
"message": "succcess"
}
#happycoding