[英]How do I print console.log on the front-end side with node.js and express
I'm learning node.js and express for a side-project. 我正在学习node.js并表示要进行副项目。
How can I print console.log();
如何打印
console.log();
on the client-side? 在客户端?
I'm working on a Hello project and I have the following code: 我正在开发一个Hello项目,并且有以下代码:
app.get('/', (req, res) => {
res.send('Hello from App Engine!');
});
Why do console.log() doesn't print in the client-side when I'm doing this: 为什么执行以下操作时console.log()不在客户端打印:
app.get('/', (req, res) => {
res.send(console.log("test"));
});
https://expressjs.com/en/api.html#res.send https://expressjs.com/en/api.html#res.send
res.send
accepts an argument which is of the following types: res.send
接受以下类型的参数:
a Buffer object, a String, an object, or an Array
缓冲区对象,字符串,对象或数组
console.log
does not return anything and therefore nothing is passed to res.send
. console.log
不返回任何内容,因此没有任何内容传递给res.send
。 Instead, you can do the following: 相反,您可以执行以下操作:
res.send(`
<!DOCTYPE html>
<html>
<body>
<script>
console.log(${ "test" /* this can be variable instead */ });
</script>
</body>
</html>
`);
This will output a script element that will log something to the client console. 这将输出脚本元素,该脚本元素会将某些内容记录到客户端控制台。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.