从restapi检索响应并在UI中显示

我试图在nodejs中调用restapi,并需要在UI中显示完整的信息或部分信息,但是我面临的问题在UI中打印响应,如果您注意到我的下面的代码,我能够打印来自htm的incident_no但是我需要打印restapi的回复。

var Client = require('node-rest-client').Client; var express = require('express'); var app = express(); Object.assign = require('object-assign'); // direct way var client = new Client(); var request = require('request') var username = 'api_batch' var password = 'batch@2016' var server = app.listen(8081, function () { var host = server.address().address var port = server.address().port console.log("Example app listening at http://%s:%s", host, port) }) app.use(express.static('public')); app.get('/restapi_get.htm', function (req, res) { res.sendFile( __dirname + "/" + "restapi_get.htm" ); }) app.get('/get_status', function (req, res) { // Prepare output in JSON format var options = { url: "https://paypal.service-now.com/api/payp2/table/incident/number/" + req.query.incident_no, auth: { user: username, password: password } } response = { incident_no:req.query.incident_no, }; request(options, function (err, res, body) { if (err) { console.dir(err) return } console.dir('headers', res.headers) console.dir('status code', res.statusCode) console.dir(body) console.log(res) }) console.log(response); res.end(JSON.stringify(response)); }) 

  <form action = "http://localhost:8081/get_status" method = "GET"> First Name: <input type = "text" name = "incident_no"> <br> <input type = "submit" value = "Submit"> </form>