From 718aa505c47eecf0ef2c28ec3a7c1f5d63a9d6d6 Mon Sep 17 00:00:00 2001 From: Kyle Robinson Young Date: Mon, 16 Apr 2012 22:15:51 -0700 Subject: [PATCH] doc: add require.extensions to globals Closes #3028 --- doc/api/globals.markdown | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/doc/api/globals.markdown b/doc/api/globals.markdown index 5df0b9e..d8fb257 100644 --- a/doc/api/globals.markdown +++ b/doc/api/globals.markdown @@ -61,6 +61,24 @@ but rather than loading the module, just return the resolved filename. Modules are cached in this object when they are required. By deleting a key value from this object, the next `require` will reload the module. +### require.extensions + +* {Array} + +Instruct `require` on how to handle certain file extensions. + +Process files with the extension `.sjs` as `.js`: + + require.extensions['.sjs'] = require.extensions['.js']; + +Write your own extension handler: + + require.extensions['.sjs'] = function(module, filename) { + var content = fs.readFileSync(filename, 'utf8'); + // Parse the file content and give to module.exports + module.exports = content; + }; + ## __filename -- 2.7.4