简体   繁体   English

Express.js和Node.js | 渲染模板

[英]Express.js & Node.js | Rendering template

1) Can I render a view with Express without using any template file like jade? 1)我可以使用Express渲染视图而不使用像jade这样的模板文件吗?

I'm building a real-time chat system for Mobile Devs (cross-platform, so it's a web app) with Node, Express & Socket.io, and the server code core will be build for dispatch messages, user's requests & so on, I don't need to have a view but the result of the functions, because the view is already running on the device. 我正在为Node Devs构建一个实时聊天系统(跨平台,因此它是一个Web应用程序),使用Node,Express和Socket.io,服务器代码核心将构建用于调度消息,用户请求等等,我不需要查看视图,而是查看函数的结果,因为视图已经在设备上运行。

That's not really rendering , just serving . 这不是真正的渲染 ,只是服务

You can send a file as answer using res.sendfile : 您可以使用res.sendfile发送文件作为答案:

res.sendfile("pathToYourFile.html");

If you just want to send the results of functions, you can simply send the response without using a template by calling the .end() method ( documentation ) of the response object that Node passes. 如果您只想发送函数的结果,则可以通过调用Node传递的response对象的.end()方法( 文档 ),在不使用模板的情况下发送响应。 An example: 一个例子:

function onRequest( request, response ) {
  functionResult = someFunctionYouWantToCall();
  response.end( functionResult );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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