title: Failed to lookup view using ejs and expressjs
body: <p>I just start learning <code>NodeJS</code> and seems amazing to me. Anyway,  I'm facing a weird issue about the view rendering. Essentially I want use the <code>MVC</code> pattern, so I organized my project in the following way:</p>
  
  <p><a href="https://i.stack.imgur.com/w7BQs.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w7BQs.jpg" alt="enter image description here"></a></p>
  
  <p>Inside <code>app.js</code> I wrote the following code:</p>
  
  <pre><code>const express = require('express');
  const app = express();
  
  require('./config/environment.js')(app, express);
  require('./config/routes.js')(app);
  
  app.listen(process.env.PORT || 3000);
  </code></pre>
  
  <p>Essentially, I declared the server using <code>expressjs</code> 'cause is indicated for <code>MVC</code> application, and then I placed all the configuration for the environment within <code>envinroment.js</code>, passing to the constructor of the module the app and the express:</p>
  
  <pre><code>module.exports = function(app, express){
  
      app.set('development', function(){
          app.use(express.errorHandler({
              dumpExceptions: true,
              showStack: true
          }));
      });
  
      app.set('production', function(){
          app.use(express.errorHandler());
      });
  
      app.set('view engine', 'ejs');
      app.set('views', __dirname);
  
      if(process.env.NODE_ENV === 'production'){
          app.set('port', 80);
      }
  };
  </code></pre>
  
  <p>as you can see I setted as <code>view engine</code> the <code>ejs</code> package, so in this way I can render html file within a javascript file and pass information to the view.</p>
  
  <p>Then in <code>routes.js</code> I wrote:</p>
  
  <pre><code>module.exports = function(app){
  
      app.get('/', function(req, res){
          res.render('home.ejs', {counter: 2});
      });
  
  };
  </code></pre>
  
  <p>this is the code that cause the problem, infact when I load my application I get:</p>
  
  <blockquote>
    <p>Failed to lookup view "home.ejs" </p>
  </blockquote>
  
  <p>I also tried using:</p>
  
  <pre><code>const path = require('path');
  res.render(path.join(__dirname+'/views/home.ejs'), {counter: 2});
  </code></pre>
  
  <p>but same problem.. </p>
  
  <p>Thanks in advance for any help</p>