简体   繁体   中英

How to sent results of request to client browser in node.js

I need to send the results of the following 'request' to the client browser, and don't know how to do it. The function is performed at the Node.js server.

var request = require("request");
function RedirectReceiver(url, currentState, callback){
    ; Send url and get back an HTML page
    request(url, function(error, response, body) {
        // body contains HTML page. Sent it to client browser
    });
};

You have to send the client a file, by using res.sendFile(__dirname + "Your file name"); when the client connect.

For it example if you want to send a client the index.html file when he connects:

app.get('/', function(req, res){

    res.sendFile(__dirname + "/index.html");
    console.log('User has reached the login page.');
});

app is var app = require('express')();

I have made a console.log('User has reached the login page.') so I can know when the client connects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM