title: Simplest possible node.js + nunjucks example
body: <p>Probably will never use node.js nor Nunjucks for any real development, but now for some reason need:</p>
  
  <ul>
  <li>precompile the some simple templates to javascript with <code>Nunjucks</code></li>
  <li>run the precompiled templates under the <code>node.js</code></li>
  </ul>
  
  <p>I have done:</p>
  
  <ul>
  <li>installed <code>node.js</code> and the <code>npm</code> (e.g. have <code>node</code> and the <code>npm</code> command)</li>
  <li><code>mkdir njtest &amp;&amp; cd njtest</code></li>
  <li>installed the nunjucks with the <code>npm install nunjucks</code> (got a <code>node_modules/nunjucks</code> directory)</li>
  <li><code>mkdir templates</code></li>
  <li><p>in the templates i have created two files <code>index.html</code> and <code>layout.html</code> with the following <code>jinja2/nunjucks</code> content</p></li>
  <li><p><code>layout.html</code></p></li>
  </ul>
  
  
  
  <pre><code>&lt;!doctype html&gt;
  &lt;head&gt;
          &lt;title&gt;simple example&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
          &lt;h1&gt;Simple example&lt;/h1&gt;
          {% block body %}{% endblock %}
  &lt;/body&gt;
  </code></pre>
  
  <ul>
  <li><code>index.html</code></li>
  </ul>
  
  
  
  <pre><code>{% extends "layout.html" %}
  
  {% block body %}
  hello world
  {% endblock %}
  </code></pre>
  
  <ul>
  <li>I precomplied the templates with the</li>
  </ul>
  
  
  
  <pre><code>./node_modules/nunjucks/bin/precompile templates &gt;templates.js
  </code></pre>
  
  <p>and in the <code>templates.js</code> I have the precompiled code.</p>
  
  <p>What I should <code>to do</code> next to get an running web-server what will use the precompiled <code>template.js</code>?</p>
  
  <p>Please, don't search anything advanced behing this question. This is probably an stupid-simple question for someone who know node and javascript.</p>
  
  <p>What i know, will need, create a file let says <code>app.js</code> and need run it with the <code>node</code> - but what should contain?</p>
  
  <pre><code>require 'nunjucks';
  </code></pre>
  
  <p>and probably something like: <code>var res = nunjucks.render('templates.js');</code> and what else? (the simplest possible (one time) solution). Note: want use Nunjucks server-side and not in the browser.</p>