Coder Social home page Coder Social logo

chat-server-challenge's Introduction

Node.js Chat Server

Overview

This project is a chat server built using Node.js, providing RESTful endpoints for user authentication, sending and receiving messages with Websockets and storing messages in a database.

Table of Contents

Features

  • User authentication with basic username/password login
  • Single chat room creation on server startup
  • Persistent storage of chat messages
  • Unit testing
  • WebSocket support for real-time chat previously with RESTful endpoints for sending and retrieval messages
  • CI/CD to deploy with Github Actions
  • Server scalability with Clustering

TODO

  • Message deletion by clients

๐Ÿ› ๏ธ Prerequisites

Non Docker

  • Please make sure to either have MongoDB Community installed locally or a subscription to Mongo on the cloud by configuration a cluster in atlas.

Docker ๐Ÿณ

  • Please make sure to have docker desktop setup on any preferred operating system to quickly compose the required dependencies. Then follow the docker procedure outlined below.

Note: Docker Desktop comes free on both Mac and Windows, but it only works with Windows 10 Pro. A workaround is to get Docker Toolbox which will bypass the Windows 10 Pro prerequisite by executing in a VM.


๐Ÿš€ Deployment

Manual Deployment without Docker

  • Create a .env file using the cp .env.example .env command and replace the existing env variables with personal settings (MongoDB URL either srv or localhost)

  • Download dependencies using npm i or yarn

  • Start the app in pre-production mode using npm run start or npm run start:dev for development (the app will be exposed on the port 9000; not to conflict with React, Angular, or Vue)

Deploying with Docker ๐Ÿณ

  • Execute the following command in-app directory:
# creates and loads the docker container with required configuration
$ docker-compose up -d 

๐Ÿ”’ Environment Configuration

By default, the application comes with a config module that can read in every environment variable from the .env file.

APP_ENV - the application environment to execute as, either in development or production. Determines the type of logging options to utilize. Options: dev or prod.

APP_URL - the base URL for the application. Made mainly to showcase the power of ConfigService and can be removed as it doesn't serve any other purpose

WEBTOKEN_SECRET_KEY - the secret key to encrypt/decrypt web tokens with. Make sure to generate a random alphanumeric string for this.

WEBTOKEN_EXPIRATION_TIME - the time in seconds indicating when the web token will expire; by default, it's 2400 seconds which is 40 mins.

DB_URL - the URL to the MongoDB collection

PORT - Application PORT

WEBSOCKET_PORT - Port for listening messages with WebSocket


โœ… Testing

Docker ๐Ÿณ

# unit tests
$ docker exec -it nest yarn test

# e2e tests
$ docker exec -it nest yarn test:e2e

Non-Docker

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

๐Ÿ“ Open API

Out of the box, the web app comes with Swagger; an open api specification, that is used to describe RESTful APIs. Nest provides a dedicated module to work with it.

The Swagger URL is http://localhost:9000/api/docs but also follows the example of Chat Challenge.postman_collection.json in the root directory.


License

Nest is MIT licensed.

Author

chat-server-challenge's People

Contributors

osgioia avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.