Why does it still say: "Cannot GET /chat.html"?

In our glitch project: https://glitch.com/~quasar-disco-trilby we are unable to GET /chat.html even though we have the line of code:

app.get("/", function(request, response) {
response.sendFile(__dirname + “/views/chat.html”);

What are we doing wrong?

Is chat.html even of a file?

There is a file called chat.html

@ThijsH04, to view the output of that file, you need to visit the route which you have defined. In the code that you have posted, if you visit quasar-disco-trilby.glitch.me/ you should be able to see what you expect.

Here’s what an express route mean:

app.get("/", function(request, response) {
   response.sendFile(__dirname + “/views/chat.html”);

This means that when you visit the route /, the file chat.html will be served. What you tried to do was you visited the route /chat.html but you have not defined that particular route.

You can do so with the following code:

app.get("/chat.html", function(request, response) {
   response.sendFile(__dirname + “/views/chat.html”);

So now when you visit the route /chat.html, you’ll see the chat.html file.

It is essential to define all the routes and the files to be served for that route or else you’ll get an error like you described in your original post.

app.get("/ROUTE_TO_VISIT", function(request, response) {
   res.sendFile(__dirname + "/PATH/TO/FILE");

The route can be anything, visiting that route will render the file you have specified.

For example:

app.get("/hello", function(request, response) {
   res.sendFile(__dirname + "/views/index.html");

// Then when you visit /hello, you'll see the output of views/index.html (if that file exists)

Make sure to read the Express documentation about routing for a better understanding: https://expressjs.com/en/guide/routing.html.

Hope this helps!


Ty sm

it works now

1 Like