# server-boilerplate **Repository Path**: tonylee838/server-boilerplate ## Basic Information - **Project Name**: server-boilerplate - **Description**: A reusable express app template with configuration and simple CRUD functionality about user authentication and authorization. - **Primary Language**: JavaScript - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-01-17 - **Last Updated**: 2021-06-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Server Boilerplate ## Description This is a server-side code boilerplate of web application using **Javascript** and **Node.js** . App is Implemented with: - Express - Mongodb/mongoose (Database) All endpoints are tested using _Jest_ library. ## Functionality - User Register/Login - Route protection(Authorization) - Error Logging ## Development Configs - webpack config - nodemon config ## Authentication This app allows user to register/login by calling corresponding api endpoint. ### User Object Model - User - type: `String` - length: 3 - 50 characters - Password - type: `String` - length: 6 - 1025 characters - Email - type: `String` (valid email address) - length : 6 - 255 characters - Each of email in the database should be **unique**. ### Register 1. Send **POST** request to `/register` endpoint. 2. User information should be passed in data section of the http request with the following structure: ```json data:{ "username":"__name__", "password":"__password__", "email":"__email@mail.com__" } ``` 3. Response When data processing and validation completes, it sends a response with _name_ and _email_ message as well as token header. 4. Error - ValidationError(status:**400**): If user sends invalid data, app will response with an Error. ### User Authentication 1. Send **POST** request to `/auth` endpoint. 2. User information should be passed in data section of the http request with the following structure: ```json data:{ "password":"", "email":"" } ``` 3. Response When login is successful, it sends authentication token in response's header and user object. 4. Error - AuthenticationError(status:**401**): Occurs when incorrect email-password combination is passed. ### Authentication Token When authentication is successful, a Jsonwebtoken is generated and sent to the client. The payload of token uses users unique *id* and *authorization level*.