Skip to content

Instantly share code, notes, and snippets.

@jkz
Created April 21, 2014 19:05
Show Gist options
  • Save jkz/11152955 to your computer and use it in GitHub Desktop.
Save jkz/11152955 to your computer and use it in GitHub Desktop.
I try to require sub-directories from a node module without success.
/moduleA
index.js
require('coffee-script/register')
require('./src')
extensions.js
require('coffee-script/register')
require('./src/extensions')
/src
index.coffee
# This is what I want to achieve in a very simplified form
# It would actually be on a class representing the module
# and the modules need to be loaded on `init` so I can set
# up some listeners and such
exports.loadExtensions = (name) ->
require "#{name}/extensions"
/extensions
index.coffee
# requires all extensions in this folder
exports.extensionA = require './extensionA'
exports.extensionB = require './extensionB'
extensionA.coffee
extensionB.coffee
/moduleB
index.js
require('moduleA'); // works
require('moduleA/extensions'); // worksn't
// This is what needs to work. In the actual code it won't appear like this,
// but rather tucked away in an init instance method.
require('moduleA').loadExtensions('moduleA');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment