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

156
Views
Gotta conflict with... itself in express

I've integrated for my bot APIs. I expected they will work very well, but the truth is no...
I still can't figure out how the server gonna abort itself... This is error output, and the code, screenshot. Just help me...

Error: Request aborted

    at onaborted (/home/runner/TModeration-Server/node_modules/express/lib/response.js:1052:15)
    at Immediate._onImmediate (/home/runner/TModeration-Server/node_modules/express/lib/response.js:1094:9) {
  code: 'ECONNABORTED'
}
// API server
const express = require('express')
const path = require("path")
const app = express()
const PORT = 443

app.get('/api/', (req, res) => {
  var options = {
    root: path.join(__dirname)
  };
  res.writeHead(200, {'Content-Type': 'text/plain'})
  const requiredFile = req.path.toLowerCase.replaceAll('https://', '').replaceAll('tmoderation-server.henry133.repl.co', '').replaceAll('/api/', '')
  res.sendFile(`./APIs/${requiredFile ?? "index.js"}`, options, function(err) { console.log(err) })
  res.end()
})

app.get('/', (req, res) => {
  var options = {
    root: path.join(__dirname)
  };
  res.writeHead(200, {'Content-Type': 'text/html'})
  res.sendFile("./html.txt", options, function(err) { console.log(err) })
  res.end()
})

app.listen(PORT || 443, () => {
  console.log(`APIs [BETA] is listening ${PORT}`)
})

image

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

0

If you want to send a static file you can use sendFile method, try this syntax with path.resolve:

app.get('/', (req, res) => {
  res.status(200).sendFile(path.resolve('html.txt'));
})

about 4 years ago · Juan Pablo Isaza Report

0

I think this error occurs because the next middleware method is not called, try this syntax:

app.get('/', (req, res, next) => {
var options = {
    root: path.join(__dirname)
  };
  res.writeHead(200, {'Content-Type': 'text/html'})
  res.sendFile("./html.txt", options, function(err) { 
  if (err) {
        next(err);
    } else {
        console.log('Sent file');
        next();
    }
  })
  res.end()
})
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!