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
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 calledstatusand is called on theresobject beforesendFile.