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

406
Views
How should I give the parameters to express.use without getting a type error?

In this code snippet in the use function the path string throws this error.

Argument type string is not assignable to parameter type RequestHandler<RouteParameters>
   Assigned type doesn't contain call signatures

How should I use the params properly?

const express = require('express');

const app = express();

app.use('/test', (req, res, next) => {
    res.send('<h1>Test</h1>');
});

app.use('/', (req, res, next) => {
    res.send('<h1>Hello World</h1>');
});

app.listen(3000);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Everything seems to be correct, but 1 thing that's bugging me is the way you are importing express. If you are using typescript you should be importing like this

import express from 'express'
about 4 years ago · Juan Pablo Isaza Report

0

It seems like you're mixing commonjs modules with typescript/es6 modules. They are compiled differently. This is why you're gettings this error, because when you required express, it was not resolved to the correct function that can be executed for you get a instance of express app.

In order make compatibility between different types of modules, you must configure typescript.

{
    "compilerOptions": {
        "module": "commonjs",
        "esModuleInterop": true,
        "target": "es6",
        "moduleResolution": "node",
        "outDir": "dist",
        "baseUrl": ".",
        "paths": {
            "*": [
                "node_modules/*"
            ]
        }
    },
    "include": [
        "src/**/*"
    ]
}
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!