Andrea Giachetto
Andrea Giachetto

Reputation: 187

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.

Upvotes: 1

Views: 488

Answers (2)

The Fonz
The Fonz

Reputation: 85

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 );
}

Upvotes: 0

Denys Séguret
Denys Séguret

Reputation: 382092

That's not really rendering, just serving.

You can send a file as answer using res.sendfile :

res.sendfile("pathToYourFile.html");

Upvotes: 3

Related Questions