Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

enhanced-require

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

enhanced-require

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

  • 0.3.1
  • npm
  • Socket score

Version published
Weekly downloads
46
decreased by-72.46%
Maintainers
1
Weekly downloads
 
Created
Source

enhanced-require

More features for node.js require.

  • loader support
  • require.ensure
  • AMD require, define (from require.js)
  • require.context

Asynchron require functions are really async. They do not use the sync node.js require, but use a async resolving and async readFile.

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

require = require("enhanced-require")(module);

// and optionally if your want require.js style defines:
if(typeof define != "function") var define = require.define;

Than you can use them:

// use loaders
var fileContent = require("raw!"+__filename);

// use loaders automatically
var template = require("./my-template.jade");

var html = template({content: fileContent});

// use require.context
var directoryRequire = require.context("raw!./subdir");
var txtFile = directoryRequire("./aFile.txt");

// use require.ensure
require.ensure(["./someFile.js"], function(require) {
	var someFile = require("./someFile.js");
});

// use AMD define
require.define(["./aDep"], function(aDep) {
	aDep.run();
});

// use AMD require
require(["./bDep"], function(bDep) {
	bDep.run();
});

Future Plans

  • require("enhanced-require/install") enables support for all modules.

License

Copyright (c) 2012 Tobias Koppers

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

FAQs

Package last updated on 08 Oct 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc