Node.js 如何在没有express的情况下重定向到其他页面

Node.js 如何在没有express的情况下重定向到其他页面,node.js,http,redirect,Node.js,Http,Redirect,服务器的代码如下所示: 在103。我有一个条件。然后我想重定向另一个页面。就像“index.html”一样,您所处的范围是req和res可用的,因此只需结束它并输出重定向头即可 if (results.length > 0) { results.forEach(function (key) { if (key.password != userParsed.password) { res.writeHead(301, {

服务器的代码如下所示:


在103。我有一个条件。然后我想重定向另一个页面。就像“index.html”一样,

您所处的范围是
req
res
可用的,因此只需结束它并输出重定向头即可

if (results.length > 0) {
    results.forEach(function (key) {
        if (key.password != userParsed.password) {
            res.writeHead(301, {
                'Location': 'your/path/file.html'
            });
            res.end();
        } else {
            console.log(key.password);
        }
    });
}