Search code examples
javascriptphpnode.jstemplate-engine

Templating library for node.js with php-like syntax


Is there a library for node.js to "parse" a content of a file with specific syntax? In example, I have a file which I want to serve on my node.js server:

<!DOCTYPE html>
<html>
<head>...</head>
<body>
    <?node echo Date.getTime(); ?> <!-- or something like this, I hope you have got the idea -->
</body>
</html>

Then it returns a HTML document:

<!DOCTYPE html>
<html>
<head>...</head>
<body>
    08.08.2013 <!-- or something like this, I hope you have got the idea -->
</body>
</html>

I don't know how to describe it more precisly, something like PHP for Apache server, but for node.js server.


Solution

  • You are talking about a template engine. There are many possibilites, one of the most popular is jade:

    http://jade-lang.com/

    It is especially good when integrated with Express frawework. You can find a big list of template engines here:

    https://github.com/joyent/node/wiki/modules#wiki-templating