This project is a simple Echo server built with Node.js and Express, demonstrating connectivity to MySQL, PostgreSQL, and Redis databases. It's designed to be run in a Docker container and can be easily configured using environment variables.
Hiring purpose
Public (readonly)
- Express.js web server
- Connectivity checks for MySQL, PostgreSQL, and Redis
- Docker support for easy deployment
- Environment variable configuration
- Password redaction in connection information output
- Docker
- Docker Compose (optional, for using docker-compose.yml)
- Access to MySQL, PostgreSQL, and Redis databases
- Clone this repository:
git clone https://github.com/yourusername/nodejs-echo-server.git cd nodejs-echo-server
- Copy
.env.txt
to.env
and fill the.env
file with the relevant informations.
PORT
: The port the server will listen on (default: 3000)MYSQL_HOST
: MySQL server hostnameMYSQL_PORT
: MySQL server portMYSQL_USER
: MySQL usernameMYSQL_PASSWORD
: MySQL passwordMYSQL_DATABASE
: MySQL database namePOSTGRES_HOST
: PostgreSQL server hostnamePOSTGRES_PORT
: PostgreSQL server portPOSTGRES_USER
: PostgreSQL usernamePOSTGRES_PASSWORD
: PostgreSQL passwordPOSTGRES_DATABASE
: PostgreSQL database nameREDIS_URL
: Redis connection URL
-
Build and run the Docker container:
Using Docker Compose:
docker-compose up --build
Or using Docker run:
inline env variables
docker build -t echo-server . docker run -p 3000:3000 \ -e MYSQL_HOST=your_mysql_host \ -e MYSQL_PORT=your_mysql_port \ -e MYSQL_USER=your_mysql_user \ -e MYSQL_PASSWORD=your_mysql_password \ -e MYSQL_DATABASE=your_mysql_database \ -e POSTGRES_HOST=your_postgres_host \ -e POSTGRES_PORT=your_postgres_port \ -e POSTGRES_USER=your_postgres_user \ -e POSTGRES_PASSWORD=your_postgres_password \ -e POSTGRES_DATABASE=your_postgres_database \ -e REDIS_URL=your_redis_url \ --network existing_network \ echo-server
or using the
.env
filedocker build -t echo-server . docker run -p 3000:3000 \ --env-file .env \ --network existing_network \ echo-server
Access the server at http://localhost:3000
GET /
: Returns a JSON object with the server status and connection information for MySQL, PostgreSQL, and Redis.
Example response:
{
"message": "Echo server is running!",
"mysql": {
"connected": true,
"connectionInfo": "mysql://user:****@mysql-host:3306/mydatabase"
},
"postgres": {
"connected": true,
"connectionInfo": "postgresql://user:****@postgres-host:5432/mydatabase"
},
"redis": {
"connected": true,
"connectionInfo": "redis://user:****@redis-host:6379"
}
}
To run the server locally for development:
-
Install dependencies:
npm install
-
Start the server:
npm run dev
This will start the server with nodemon, which will automatically restart the server when you make changes to the code.
This project is licensed under the ISC License.