1

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.

3
  • Yes, you can use EJS which looks like HTML with a few extra tokens to allow you to insert dynamic text. Commented Mar 18, 2014 at 13:36
  • Your question isn't clear : do you want to use a HTML file and no template (that's what my answer assumes) or do you want to use a template more like HTML (what @HectorCorrea seems to have understood) ? Commented Mar 18, 2014 at 13:41
  • I need to handle only the results of the functions without template or view. Thanks for the answer. Commented Mar 18, 2014 at 13:49

2 Answers 2

3

That's not really rendering, just serving.

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

res.sendfile("pathToYourFile.html");
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.