title: Node js and ejs using loop
body: <p>I am new to node.js and now I am facing a problem with EJS template. I noticed my <code>for</code> loop is not running though the EJS template. I tried to make a very basic todo app. </p>
  
  <p><strong>Here is the hierarchy of the project I made</strong></p>
  
  <p><a href="https://i.stack.imgur.com/WgEHT.png" rel="nofollow noreferrer">This is my project hierarchy</a></p>
  
  <p><strong>This is my App js module</strong></p>
  
  <pre><code>let express = require('express');
  let todoController = require('./Controller/todoController')
  let app = express()
  app.set('view engine', 'ejs');
  todoController(app);
  
  
  
  
  app.listen(3000,function(){
  console.log('server started on http://localhost:3000');
  })
  </code></pre>
  
  <p><strong>todoController.js</strong></p>
  
  <pre><code> let toDoList = ['Go to university','Smoking sigrate'];
      module.exports= function(app){
          app.get('/', function(req, res){
              res.render('index.ejs', {toDoList: toDoList});
          });
  
          app.get ("*", function(req,res){
              res.send("&lt;h1&gt;Invalid page&lt;/h1&gt;");
          })
      }
  </code></pre>
  
  <p><strong>index.ejs</strong> </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  
  &lt;head&gt;
    &lt;title&gt;Todo&lt;/title&gt;
    &lt;link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
      crossorigin="anonymous"&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  
  
    &lt;!-- As a heading --&gt;
    &lt;nav class="navbar navbar-light bg-dark"&gt;
      &lt;span class="navbar-brand mb-0 h1 text-white"&gt;Todo List&lt;/span&gt;
    &lt;/nav&gt;
    &lt;br&gt;&lt;br&gt;
    &lt;div class="container"&gt;
      &lt;form&gt;
        &lt;div class="form-group text-white bg-dark"&gt;
          &lt;label for="formGroupExampleInput2"&gt;Enter to do item&lt;/label&gt;
          &lt;input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Input a item to do list...."&gt;
          &lt;input type="submit" class="form-control bg-primary text-white h3" &gt;
        &lt;/div&gt;
      &lt;/form&gt;
    &lt;/div&gt;
  
    &lt;br&gt;&lt;br&gt;
      &lt;div class="row"&gt;
      &lt;ul class="col-6 mx-auto" &gt;
  
        &lt;% for(let i =0; toDoList.length; i++){ %&gt;
          &lt;li&gt; &lt;%= toDoList[i] %&gt; &lt;/li&gt;
        &lt;% } %&gt;
  
      &lt;/ul&gt;
    &lt;/div&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>