javascript - express node.js making a get request to another server from node route -


so client makes request using button on index page. sends information route has been set follows:

app.js

var route = require('./routes/index'); var button = require('./routes/button'); app.use('/', index); app.use('/button', button); 

the request sent client-side directory node framework whenever presses button. if request sent 'localhost:port/button', button.js file mentioned above receive request. in button.js file have following:

var express = require('express'); var router = express.router(); var somedata = '';  router.get('/', function (req, res, next) {     //make request here such somedata     //receives whatever request returns     //set framework(i.e. spring...)     somedata = getrequest('some other url');     res.send(somedata); }; module.exports = router; 

the problem here getrequest('some other url') within router request never receives information.

also (as side-note), cannot seem find in express api why have

router.get('/')... 

instead of

router.get('/button')... 

to access , make requests button page.

any appreciated!

you want make request other rest api running somewhere else right? can use node-rest-client that.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -