1

My is there c:\nodejs\www\project\bin\server.js

My views are in c:\nodejs\www\project\views

Then in my server.js I have:

.set('views', __dirname + '/views')

But the generated path is: c:\nodejs\www\project\bin\views

How to get the parent of bin folder?

I use Express and Ejs.

Regards

Syl
  • 2,232
  • 8
  • 34
  • 45
  • see this : [http://stackoverflow.com/questions/7083045/fs-how-do-i-locate-a-parent-folder][1] [1]: http://stackoverflow.com/questions/7083045/fs-how-do-i-locate-a-parent-folder – bestpostmaster Jun 21 '13 at 14:39
  • I don't understand how to adapt that code for me. I'm a Node.js beginner. – Syl Jun 21 '13 at 18:52

1 Answers1

3

there are two ways of doing this, I can think :

  1. .set('views',__dirname + '../views');

Or

  1. you can use path.join from the path module

    var path = require("path"), .set(path.join(__dirname, '..', 'views'));

these will get your back one parent in the directory structure to find the file.

Naeem Shaikh
  • 15,331
  • 6
  • 50
  • 88