Express.js and ws "Cannot GET /" error in browser

I am having an issue in my project when I use this code
https://replit.com/@LucienDuchateau/Texas-Holdem-Ws-1#index.js
This is what happens


I’ve tried some things such as porting to other ports, trying without public, trying ws and wss, ect.

Please help, thanks.

Hello @LucienDuchateau, welcome to the community!
If you want to output something to the webpage, you are going to need to use app.get() and send some text or html file because right now you haven’t set up any way to see output on the / route.

Example:

app.get("/", (req, res) => {
    res.send("Hello, World!");
});
1 Like

@SharkCoding This makes the html page have Hello world, however I want it to display the index.html file which has the html for the full game, how can I do this with your code?

Instead of res.send() use res.sendFile(). Also take a look at the expressjs docs

@SharkCoding Thanks a lot! The html and css are now working and I am no longer getting that error. For some reason the ws isn’t being recognized on startup, however I believe the express part of this works. Thanks!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.