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

require-from-url

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

require-from-url - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

fetch.js

2

package.json
{
"name": "require-from-url",
"version": "3.0.0",
"version": "3.1.0",
"description": "Require module from URL",

@@ -5,0 +5,0 @@ "main": "./index.js",

# require-from-url
Load module from URL in Node.
## Install
```

@@ -12,15 +10,10 @@ $ npm install require-from-url

## Usage
```js
var requireFromUrl = require('require-from-url');
requireFromUrl(["https://nodeway.org/HelloWorld.js"], function(err, HelloWorld) {
if(err) return;
var api = new HelloWorld.default;
api.hello('world', (err, greeting) => console.log(greeting));
});
var requireFromUrl = require('require-from-url/sync');
var HelloWorld = requireFromUrl("https://nodeway.org/HelloWorld.js");
var api = new HelloWorld;
api.on('data', console.log);
```
## License
MIT © [May xiaoya zhang](gzhangzy@gmail.com)

@@ -1,40 +0,11 @@

var path = require("path");
var proto = {
http : require("http"),
https : require("https")
};
var crypto= require('crypto');
var fetch = require("./fetchFromUrl.js");
var requireFromString = require("./requireFromString.js");
function requireFromString(code, filename) {
var Module = module.constructor;
var m = new Module(filename, module.parent);
m.filename = filename;
m.paths = Module._nodeModulePaths(path.dirname(filename));
m._compile(code, filename);
return m.exports;
}
function md5(str) {
var md5sum = crypto.createHash('md5');
md5sum.update(str);
return md5sum.digest('hex');
}
function requireFromUrl(url, callback) {
proto[url.protocol.slice(0, -1)].get(url, function(res) {
var str = "";
res.on("data", function(data) {
str+= data;
}).on("end", function() {
switch(res.statusCode) {
case 200:
callback(requireFromString(str, __dirname+'/'+md5(url.href)+url.path));
break;
default:
callback(new Error("href="+url.href+"; statusCode="+res.statusCode));
}
});
}).on('error', callback);
fetch(url, function(err, str, filename) {
err ? callback(err)
: callback(requireFromString(str, filename));
});
}
module.exports = requireFromUrl;
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