0% found this document useful (0 votes)
18 views

Mysql Authentication, Nodejs and Docker

This document outlines a Node.js authentication API project that uses MySQL for database management and Docker for containerization. It details the project layout, prerequisites for setup, and instructions for running the API locally and accessing protected routes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Mysql Authentication, Nodejs and Docker

This document outlines a Node.js authentication API project that uses MySQL for database management and Docker for containerization. It details the project layout, prerequisites for setup, and instructions for running the API locally and accessing protected routes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Node.

js Authentication with MySQL and Docker

This project is a robust authentication API developed using Node.js. It leverages


MySQL for database management and Docker for containerization. The API ensures
secure user authentication and is comprehensively documented with Swagger for ease
of use and integration.

Table of Contents

- Quick Links
- What You Need
- Key Features
- Project Layout
- Prerequisites
- Installation and Setup
- Using the App
- API Routes - Protected
- Credentials

Quick Links

- MySQL
- Docker
- OpenAPI 3.0

What You Need

- Node.js
- IDE
- Docker
- MySQL

Key Features

- User authentication bolstered with CORS support.


- Interactive API documentation facilitated by Swagger.
- Docker containerization for simplified deployment and scalability.
- Distinct environment configurations for development and production stages.

Project Layout

The project's directory structure is as follows:

- config/: Houses database configurations and other environment variables.


- controllers/: Contains control logic for authentication and protected routes.
- db/: Holds the database connection configuration.
- docs/: Contains API documentation in YAML format for Swagger.
- environment/: Contains environment variable files for different environments.
- routes/: Defines the API routes.
- services/: Contains services related to the user.
- Dockerfile and docker-compose.yml: Files necessary for Docker containerization.

Prerequisites

- Docker and Docker Compose (for containerization).


- Node.js (version 14.x or higher).
- MySQL (version 8.x or higher).

Installation and Setup


To start a new Node.js project, you can use the npm init command. The -y flag will
automatically fill in the default information in the setup process.

npm init -y

Navigate to the project directory:

cd Auth-Tutorial-Lab02

Install the necessary dependencies:

npm install

Using the App

Start the server with:

npm start

The server will run on http://localhost:3000/docs/

API Routes - Protected

Access to a protected resource requires basic authentication


http://localhost:3000/docs/Protected

Credentials

The project uses basic authentication to protect the /protected route. When making
an HTTP request to this route, you need to include these credentials in the
Authorization header of the request. The format is Authorization: Basic
{credentials}, where {credentials} is the Base64 encoding of the username and
password joined by a colon.

Use the following credentials for testing:

Username: basicUser
Password: basicPassword

You might also like