Skip to content

BackEnd сервер для управления данными компании на удаленном сервере | BackEnd server application for Company Data management

License

Notifications You must be signed in to change notification settings

yunusmi/company_crud_app_backend

Repository files navigation

Документация на русском доступна здесь

BackEnd server for company data management

This application is a backend server for managing company data such as employees, sales, products, branches, and inventory. The frontend part is available here.

Technologies Used:

  • NodeJS
  • Express framework
  • TypeScript
  • ORM: Sequelize
  • Database: MySQL
  • Caching system: Redis
  • API Documentation: Swagger (available in the development environment at URI: /api-docs/v1)

The client and server communicate via the HTTP protocol using REST API architectural style in JSON format.

Setup

Prerequisites:

  • MySQL database version 5.7 or higher
  • NodeJS version 17.0 or higher
  • Docker and Docker Compose
  • Stable internet connection (required for downloading necessary dependencies)
  1. To start the setup, create a project folder and clone the remote project repository:
    git clone https://github.com/yunusmi/company_crud_app_backend.git .
  2. Next, install the project dependencies with the command:
    npm install
  3. After installing the dependencies, create a MySQL database for the application, which is then specified in the project configuration file.
  4. After creating the database, create a .env configuration file based on the .env.example template and insert the necessary data for the application.

Parameter Description:

  • APP_PORT - specifies the NodeJS application port (default is port 3000)
  • APP_HOST - NodeJS application host (default is localhost)
  • DB_DEV_HOST - database host for the development mode (if the database is installed locally, leave it as 127.0.0.1)
  • DB_DEV_USERNAME - database username for development mode (dev)
  • DB_DEV_PASSWORD - database password for development mode (dev)
  • DB_DEV_NAME - database name for development mode (dev)
  • DB_DEV_DIALECT - database type (default is mysql)
  • DB_PROD_HOST - database host for running the application in production
  • DB_PROD_USERNAME - database username for running the application in production
  • DB_PROD_PASSWORD - database password for running the application in production
  • DB_PROD_NAME - database name for running the application in production
  • DB_PROD_DIALECT - database type (default is mysql)
  • REDIS_HOST - Redis host (default is localhost)
  • REDIS_PORT - Redis port (default is 6379)
  • REDIS_DB - Redis database number (default is 0)
  • REDIS_EXPIRE_TIME - Redis key expiration time (in seconds, default is 50)

Note: The environment can be either development (for development purposes) or production (on a remote server). For each of them, you need to specify a separate database. Before deploying the application on a production server, it is recommended to test and run the application in development mode (on a local PC), and only then deploy the application on a real production server.

Database Table Migration and Initial Data Seeding

To create the necessary tables for the application, you need to perform a table migration and then seed them with initial data.

Run the command:

npm run db:migrate:up:development

The system will automatically create the necessary tables for the application using the database configuration data.

After the tables are created, they need to be seeded with initial data.

To do this, use the command:

npm run db:seed:all:development

The system will automatically insert the initial data and populate the application's database tables.

Running the Application

To run the application on a local server (development), follow these steps:

  1. Start the Redis container via Docker with the command:
    docker run --name redis -d -p 6379:6379 redis
  2. Start the application:
    npm run start:development

Now you can run the FrontEnd client, remembering to specify the address and port of the Backend application in the client configuration file (before compilation, the config.js file).

This completes the setup and running of the application in the local (development) environment. You can modify and enhance the application's functionality. The following instructions are for setting up the application on a production server (e.g., if you have updated the application's functionality and want to deploy it on a remote server).

Setting Up the Application on a Production Server

First, create a project folder and upload the project files to the remote server using FTP or git (use the command on the remote server: git clone https://github.com/yunusmi/company_crud_app_backend.git .)

Create a .env file based on the .env.example template and fill in the parameters for the production environment.

Next, create a Docker image for the application with the command:

docker-compose build

This will start the image build process, during which all Node.js dependencies will be installed, and tables will be initialized from the migration files (see the migrations folder), and initial data will be seeded into these tables as specified in the seeders folder.

After the image is built, you can run a container based on this image:

docker-compose up -d

which will start the container in the background.

The application is now available remotely.

To view logs and debug errors, use the command:

docker logs company_data_management_app

To stop the application, use the command:

docker-compose down

Additionally, you can set up a domain, change the application port, and configure HTTPS for secure communication between the client application and the remote server.

Also, remember to update the client's configuration with the new server details (address, protocol, and port).

Conclusion

This project is distributed under the MIT license. You can use all the code from this project in your projects absolutely free.

If you need my help or consultation, you can contact me by email: contact@yunus-mil.ru.

About

BackEnd сервер для управления данными компании на удаленном сервере | BackEnd server application for Company Data management

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published