Babylon and Express, serveStatic

Novice to Node.

I’ve created a few games using Babylon, and have found it to be a very effective tool.

I’ve also created a simply user login webserver using Express and ejs. However, when I try to put my Babylon app behind the Express login, and use serve-static to access the Babylon files, I get a 404. I am relatively certain I have the paths correct. Inside the root I have a folder called Games that has the files for the Babylon game I created.

const serveStatic = require(‘serve-static’)
app.use(serveStatic(’/Games’));

When I call the express route for the game, I properly output a console.log indicating that the game .ejs is being executed, but calls to static files fail with a 404. Perhaps this is more of an Express question, but thought I would ask it here.

Forgive me if I am getting my terminology wrong, I am an old C++/C# game programmer who is tinkering with web programming for the first time.

thanks.

1 Like

hi JakeMN - welcome to the forums. On newer express you can just use express.static.

import express from "express";
const app = express();
app.use(express.static(pathToGames));
...

Serving static files in Express.

2 Likes

You know, I could have sworn that was the first setup I had, and when it didn’t work I went down a rabbit hole hacking away for a tweak that would make it work.

That being said, what you have worked perfectly, so I offer my sincere thanks. :+1: :+1:

2 Likes