A Local Webserver for Babylon.js
This tutorial:
- Is for you if you have no or limited experience with web development or servers in general.
- Will show you how to set up and start a simple, local Node.js web server for your Babylon.js application.
- Is primarily focused on Windows.
Nodejs & NPM
If you already have Node.js and NPM installed, skip to the Sample section.
Download the latest LTS Node.js installer from https://nodejs.org/en/download/
Run the installer and follow the Node.js setup wizard. The default settings are fine for our use.
NPM is included in this installation.
Sample
Now that Node.js and NPM are installed, we're ready for the server code.
- Create a folder for your project.
In this tutorial, we'll use C:\babylon
- Download the sample server master.zip
- Extract the .zip file contents to C:\babylon.
Your C:\babylon folder should now look something like this:
C:\babylon\public\C:\babylon\public\index.htmlC:\babylon\public\babylonScene.js
C:\babylon\package.jsonC:\babylon\readme.mdC:\babylon\server.jsC:\babylon\Windows_NPM_INSTALL.BATC:\babylon\Windows_START.BATOn Windows
- In File Explorer, navigate to C:\babylon.
- Double-click Windows_NPM_INSTALL.BAT
- Wait for the BAT window to finish running and close itself. This executes
npm install --save.
A new node_modules folder should be created.
- Double-click Windows_START.BAT. This executes
node server.js - A new BAT window should open:
C:\babylon>node server.jsServer is listening on port 80- Your server should now be running. Note: Closing this window will shut down the Node.js server again.
- In your browser, navigate to http://localhost/
- If the BAT file closes immediately, please check that the previous steps were completed correctly.
- To view errors, in a CMD or PowerShell window run
C:\babylon> node server.js
Other OSes
- See the npmjs.org and nodejs.org documentation for instructions.
- Execute "npm install --save" on C:\babylon
- Execute "node server.js" on C:\babylon
If anyone wishes to expand this section, feel free to open a PR.
Public Folder
In the Public folder, you'll find a sample scene consisting of an index.html file and a babylonScene.js file.
The browser's access is restricted to this folder and its files and subfolders.
You're now ready to start your project.