Next, we need to update app.js to include the SocketIO library.
To do this, run the following command at the root of our project: npm install -save socket.io. To get started with SocketIO, we need to install the library in our project and we will do that using NPM. For our game, we will be using SocketIO for sending messages for the following events: If you are not familiar with SocketIO, it is a JavaScript library for real-time web applications that allows bi-directional communication between our server and the client-side logic. With the project up and running, we will now start work on adding SocketIO to our game. For our game, normally the player would be required to login before they can access this page. Note: Currently, our server has been modified to allow anyone to access the game page, which will make it easier to test changes while developing. In your browser, if you navigate to you should see the game page. If you visit you should see the login page. In your terminal, you should see a message about being connected to mongo and that the server has started. env file, you can start the server by running the following command: npm run start. Once everything is installed and you have updated your. For this tutorial, we will not be using a version control system.
In case you will be using a version control system with your project code (like git), it is a best practice to make sure this file does not get committed with your source code and it is usually best to add the.You can also pass in these values through the terminal when you run your server code, but for the purpose of this tutorial, we will be loading them in through the.If you would rather not, you will still be able to follow along with this tutorial. We will not be covering that code in depth in this tutorial, and it is recommended that you go through those two tutorials. The Phaser game instance will be the one from the turn-based RPG tutorial. This starter code is going to set up our Node.js server that includes user authentication, login and sign up pages, and a Phaser game instance. Creating a Phaser 3 Leaderboard with User Authentication using Node.js + Express + MongoDB – Part 1.