This is a server-side implementation of Conway's Game of Life using Nodejs and Socket io along with a React frontend.
Ths server is currently hosted on heroku.
If you haven't already, go ahead and download the lastest LTS version of node as npm would be needed to complete the installation.
npm install
npm run dev
A express development server will be started on http://localhost:8080/
.
In the project directory, you can run:
Runs the server in production mode pointing to the build in the dist
folder.
Builds the server for production to the dist
folder.
Runs the server in development mode on http://localhost:8080/
.
Runs any test in the folder marked as *.spec.ts using mocha.
-
Make sure your terminal location is the root of your project.
-
In you terminal
heroku create
orheroku create [your-project-name]
.
A remote pointing to your new heroku app has already been setup by heroku create
. To deploy, simply push a master branch to the heroku remote with git push heroku master
.
Heroku has tons of methods around deployment. If manual deployment does not fit you need please check out their deployment documentation for CI/CD integrations.
I decided to use Nodejs
and Socket io
to create a realtime server with a web application structure in mind. Nodejs was used for it's single threaded model with event looping that would allow the server to respond in a non blocking manner. Socket io was used for it's realtime bi-directional communication between the server and the client using the websocket protocol.
I was not able to set up error handling with sockets due to the time constraint. For better error handling in the future, I would implement a try/catch that would emit an error on catch with a key that would allow the frontend to correctly throw a user friendly error message.
To keep the client board as synchronized as possible with little side effects, a brute forced approached was used to sent board updates to all clients. Everytime an event pertaining to the update of the board was triggered, the board would be recalculated on the server-side and a whole new board would be sent back to the clients. A more optimized approach would be to compare the old board with the new board and send an array of cells that needed to be updated, allowing less data to be sent from the server to the client(s). The frontend would then be able to recalculate the board and trigger rerender.