Enhance the require function in node.js with support for loaders which preprocess files and really async require (AMD). Enables Hot Code Replacement.


This module added loader support to node.js.

It offers features availible in webpack to node.js.

Add this line to a node.js module to active the enhanced features in that module.

require = require("enhanced-require")(require.valueOf());

Than you can use them:

var template = require("./my-template.jade");
var fileContent = require("raw!"+__filename);
var html = template({content: fileContent});
var directoryRequire = require.context("raw!./subdir");
var txtFile = directoryRequire("./aFile.txt");
  • require("enhanced-require/install") enables support for all modules.

Copyright (c) 2012 Tobias Koppers

MIT (http://www.opensource.org/licenses/mit-license.php)