Questions tagged [run-middleware]

5 questions
32
votes
5 answers

Calling already defined routes in other routes in Express NodeJS

I am writing a web app in node.js using Express. I have defined a route as follows: app.get("/firstService/:query", function(req,res){ //trivial example var html = ""; res.end(html) }); How do I reuse that…
user1148710
  • 323
  • 1
  • 3
  • 4
26
votes
3 answers

Is it possible to call Express Router directly from code with a "fake" request?

Tangential to this question, I would like to find out if there is a way of triggering the Express Router without actually going through HTTP?
oligofren
  • 20,744
  • 16
  • 93
  • 180
19
votes
5 answers

Express call GET method within route from another route

I have multiple routes. How can I get the data from the user's route (GET method), by calling it within the GET method of the group's route? What is the best way of doing this? My app.js looks like this: var express = require('express'); var routes…
asuciu
  • 1,234
  • 2
  • 21
  • 35
12
votes
4 answers

How can I trigger a route handler manually in express js?

suppose I have a simple express js application like the following: var express = require('express'); var app = express(); app.get('/', function(req, res) { return res.json({ hello: 'world' }); }); module.exports = app; I want to be able to go…
brielov
  • 1,887
  • 20
  • 28
0
votes
1 answer

Run a route by code in expressjs

So as the title says. I need to call a route from another route. I have used run-middleware npm module but after using it Morgan showing odd outputs, like showing two http request but both are same. Also accessing invalid route not going to catch…
Jayadratha Mondal
  • 759
  • 1
  • 10
  • 21