This is a Repository for the Fans-CRM Technical interview performed by Bryan Asega on using the
Nest.js framework, MySQL, and JWT authentication.
The steps performed are as follows:
- Install Node.js
- Set up development environment in Visual Studio Code (VSCode)
-
Initialize a new Nest.js project using the Nest CLI:
npm install -g @nestjs/cli
nest new nestjs-rest-api
-
Navigate to the newly created project directory and start the Nest.js server:
cd nestjs-rest-api
npm run start
-
Install Sequelize ORM and MySQL dialect for Sequelize:
npm install --save @nestjs/sequelize sequelize mysql2
-
Install JWT module for authentication:
npm install --save @nestjs/jwt passport passport-jwt
- Set up MySQL database connection in the
config
directory. - Configure Sequelize to connect to MySQL database in the
config
directory.
-
Generating a new module for users:
nest generate module user
-
Generate a user controller and service:
nest generate controller user
nest generate service user
- Define a user entity using Sequelize model in the
user
directory. - Define attributes :
id
,name
,email
,email
### Implementing Authentication
- Create an authentication module with JWT token generation and validation.
- Implementing the JWT strategy using Passport.js.
### Implementing REST Endpoints
- Defining a POST endpoint to add a user (
/api/v1/add-user
). - Defining a GET endpoint to get a user by ID (
/api/v1/get-user/:id
). - Implementing corresponding controller method to handle requests and interact with database.
### Test the Application
- Performing unit tests for services, controllers, and authentication logic.
- Using curl; testing REST API endpoints.
-
Starting Nest.js server:
npm run start:dev
### Future Development steps
- Deploy the application to a production server.
- Monitor and maintain the application ensuring its reliability and performance.