0

I have this code

const express = require('express');
const app = express();

const homepage = `${__dirname}/views/index.html`;
const errpage = `${__dirname}/views/404.html`;
const maincss = `${__dirname}/views/Assets/css/main.css`;
const mainjs = `${__dirname}/views/Assets/js/script.js`;
const skull = `${__dirname}/craneo.OBJ`

//pages
app.get("/skull.obj", (req, res) => res.sendfile(skull))
app.get("/", (req, res) => res.sendFile(homepage));
app.get("/style.css", (req, res) => res.sendFile(maincss))
app.get("/script.js", (req, res) => res.sendFile(mainjs))
app.get("*", (req, res) => res.sendFile(errpage)).code(404);

app.listen("80", () => {
    console.log('server started');
});

in line 15 i appended app.get("*", (req, res) => res.sendFile(errpage)) with .code(404); i tested this and inspect element said this gave me a code 200 i am not sure what is the problem i followed the instrutions from this answer and i am not sure what the problem with this code is and i new to express

1
  • Where exactly do you see code(404) in the linked answer? Programming by guessing doesn't work well. You can't randomly throw words into your code and expect it to work. It's important that the method is called status and is called on the res object before sendFile. Commented Nov 4, 2021 at 17:55

1 Answer 1

0

It should use res.status(xxx) instead of res.code(xxx) like so:

app.get("*", (req, res) => res.status(400).sendFile(errpage));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.