简体   繁体   中英

Express.js & Node.js | Rendering template

1) Can I render a view with Express without using any template file like 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.

That's not really rendering , just serving .

You can send a file as answer using 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. An example:

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

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