Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

297
Views
node.js - How are Status Codes Added to Express

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

app.get("*", (req, res) => res.status(400).sendFile(errpage));
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!