Sign inSign up

artemr87/node1

By artemr87

•Updated about 2 years ago

Image
0

150

artemr87/node1 repository overview

Dependencies and Setup: The server uses several Node.js packages including express for the web framework, path for directory manipulation, body-parser for parsing request bodies, multer for handling file uploads, and cookie-parser for handling cookies. Additionally, it uses cluster to fork multiple worker processes to make use of all available CPU cores, enhancing performance and scalability. Clustering Setup: • The os module is used to determine the number of CPUs available. • If the process is the master, it forks a worker for each CPU, resulting in a scalable and distributed server environment that can handle more incoming requests efficiently. • If a worker crashes with a non-zero exit code, the server automatically restarts the worker to ensure uptime. File Upload Configuration: • Uses multer to configure file uploads. Files are stored in an uploads/ directory and given unique filenames to avoid conflicts. Error Simulation: • Two types of errors are simulated for demonstration: CriticalError and NonCriticalError. • Critical errors are logged and cause the worker to terminate, while non-critical errors are logged but handled without crashing the worker. Centralized Error Handling: • The server uses centralized error handling to catch critical and non-critical errors. Critical errors cause the process to exit, while non-critical errors return a 500 status code to the client. Serving Static Files: • Serves static files from a directory named dist where a React app is built. It provides an endpoint (/basis-react-app) to access the React application. Server Startup: • Each worker starts a server on the defined port (PORT), which is 3000 by default. The master process manages these workers, improving scalability and resilience.

Usage with Two Ports

The current setup uses one port (3000) to serve both the backend API and the static files from the React application. If you want to run the backend API and the frontend app on two different ports, you would need to modify the setup as follows. So to run container:

docker run -d -p 3000:3000 -p 3001:3001

Tag summary

Content type

Image

Digest

sha256:093637873…

Size

79.5 MB

Last updated

about 2 years ago

docker pull artemr87/node1