Install Server Locally
You can install Mongo and NodeJS locally to test the server without hosting it on the cloud. This can help for development.
Install NodeJS and Mongo on Windows
Install the LTS version of NodeJS
Download and Install MongoDB community
https://www.mongodb.com/try/download/community
And Mongo Compass to access the database with an interface (It may have installed already when installing MongoDB).
https://www.mongodb.com/products/compass
You can open windows services to see if Mongo is running (Start -> search for "services"), then search for Mongo in the list of services. You can also use this Services window to restart mongo if needed.
Inside Assets/NodeJS, there is a folder containing all the server code. Unzip it in a new project folder outside of your Unity Project (to prevent Unity from generating a meta file for each file).
Once the files are unzipped, open windows command line (click on Start-> type CMD)
Navigate to your NodejS code folder, where you extracted the files, that folder should contain the server.js file and package.json file.
Install the NodeJS modules
Then try to run node
Click ctrl-C at anytime to exit
You should now be able to access the API either from the unity Unity or from Insomnia.
To access from Unity, make sure that Resources/ApiData has the api path set to 127.0.0.1, https is turned off, and then run the Demo scene. And try registering a new user.
If you want to edit the api code, I would suggest to use an IDE such as Visual Studio Code.
Use Mongo Compass to check the database
Open Mongo compass, click on new connection, and enter this string
If it connects correctly, you can click on userdb to see your current data.
If userdb doesn't appear on the left, it may be because there is no data yet. To add data you can register a new user, either through the Unity demo, or with Insomnia.
If you click on "users" you should be able to see the list of all current active users and their data.
Demo Config
In Unity, go to Resources/ApiData
From that file, you can set the api url and whether it is using https or not.
To test locally, use these config
Api URL: 127.0.0.1
Api Https: false
And then run the Demo scene.
In newest versions of Unity (2022+), HTTP is blocked by default and only HTTPS is allowed, but since our API doesn't have a SSL certificate yet, we need to test with HTTP. To allow HTTP request, go in Edit -> Project Settings -> Player Settings -> Other Settings -> Allow Download over HTTP.
Last updated