Shikhar Saxena
Shikhar Saxena

Reputation: 162

Requiring a folder with same name as file in Node

I created a file named joke.js which exports a function. I also have a folder in the directory with the same name joke. In my node file, I want to use require to reference the folder and not the file. How do I tell Node to do that?

Folder Structure

So from the index.js in the root, I want to reference the joke directory and not the joke.js file. I did: var joke=require('./joke');

P.S.- This question is just out of curiosity of how NodeJS works.

Upvotes: 2

Views: 805

Answers (1)

Kshitij Saxena
Kshitij Saxena

Reputation: 940

require('./joke/')

A trailing slash is used to specify directory in any URI.

Upvotes: 2

Related Questions