Questions tagged [express-router]

No guidance has been provided for this tag at the moment.

Sometimes, Express may return the message "not found" on and off

After working with express for many years, I find myself a bit out of practice with TypeScript - and it seems like my eyesight is failing me! This is the first time I've encountered this issue, so I must be missing something... My current dilemma is as fo ...

The route in my Node.js Express application appears to be malfunctioning

I am facing an issue with my app.js and route file configuration. Here is my app.js file: const express = require('express'); const app = express(); const port = process.env.PORT || 8080; const userRoute = require('./routes/user.route' ...

What is the best way to create a regex pattern that can match both mandatory and optional characters in a route path?

I'm having trouble creating a route path that can match both mandatory and optional characters. Here's my current route: expressRouter.get(['/post/:PostID([0-9]+)(-*)?'], async function (req, res) { let Result; const PostID ...

Strategies for capturing a 404 error in an Express router

Trying to capture the 404 page not found error in an express router. Using a simple example : const express = require('express'); const app = express(); const router = express.Router(); // ROUTER MID BEFORE router.use((req, res, next) => {console.lo ...

Having trouble with expressJS routing, basic problem not getting resolved

After organizing all my route code into separate files, I've noticed that my route resolution is inconsistent. Here's a basic example - Code in my app.js file const express = require('express'); const app = express(); var dataLoader ...

Having trouble getting the express router to function properly in your Node.js TypeScript project?

One of the components in this application is registerClass, where all routes are added. The source code is in the dist directory since this node app is using TypeScript. However, when calling the http://localhost:9001/user endpoint, it seems that it is not ...

Exploring request parameters within an Express router

I'm currently facing an issue with accessing request parameters in my express router. In my server.js file, I have the following setup: app.use('/user/:id/profile', require('./routes/profile')); Within my ./routes/profile.js fil ...

How does the router.get('/') function in Express handle requests in the routes directory that are not '/'?

My code structure is set up as follows: const routes = './routes/' const usersRouter = require(routes +'users'); /*more code*/ app.use('/users', usersRouter); Within the users.js file, I have set up the following: const express = require('express'); con ...

Why am I not receiving the expected feedback after submitting a request for a specific parameter in a Node.js and Express Router REST API?

Developed a Node module utilizing the Express router to facilitate the routes for the dishes REST API. Index.js file: const express = require('express'); const http = require('http'); const morgan = require('morgan'); const bodyParser = require('body-pars ...

Validating email IDs in an array with express-validator

Consider this scenario where a post request is made with the following body: { "from":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d5b8a7fbad95b0adb4b8a5b9b0fbb6bab8">[email protected]</a>&qu ...

Errors from Mongoose do not get propagated from the router to the app layer

There is a single API application set up like so: const express = require('express') const app = express() const router = require('express').Router() ... route.post('/dogs', (req, res, next) => { const dog = new Dog() // defined in the actual applica ...

Express.js: Defining a base route can cause issues with resolving static files

I'm currently working on a project using express.js and react.js, but I've encountered some issues that I can't seem to find solutions for. I have set up a base directory where the express server is located, and within that, there's a ...

What are the steps to redirect from a nested route back to the top route using Node.js with Express?

Is there a way to redirect from a nested route to a top route in Express.js? In the following code snippet, how can we make the callback for the route /toproute/nested redirect to /profile instead of /toproute/profile? // app.js const express = require(& ...

Unable to verify token within JWT Express middleware

I am encountering an issue with the validation of JWT tokens. When sending a GET request using Postman, the validation process fails to work as expected. Surprisingly, the request can go through even without a token. My concern is regarding utilizing this ...

What could be the reason behind receiving a Req.Req (Nested request) when using this specific configuration in Express?

IMPORTANT NOTE: If you are experiencing issues with nested requests or responses, make sure to check the parameter order or utilize the express.router({mergeParams: true}) option. It seems like my requests are being encapsulated by an additional object re ...