I'm currently trying to import one of my scripts from an URL, but the require
function doesn't appear to be working in this case.
var functionChecker = require("http://javascript-modules.googlecode.com/svn/functionChecker.js");
This is an excerpt of the error message that was produced by this script:
Error: Cannot find module 'http://javascript-modules.googlecode.com/svn/functionChecker.js'
Is there any way to import a script from an URL in node.js?
I finally got it to work. This example downloads the file http://javascript-modules.googlecode.com/svn/functionChecker.js, and then saves it in a local directory.
//var functionChecker = require(__dirname + '/functionChecker.js');
//functionChecker.checkAllFunctions(__filename);
var http = require('http');
var fs = require('fs');
var google = http.createClient(80, 'www.google.com');
var request = google.request('GET', '/svn/functionChecker.js',
{'host': 'javascript-modules.googlecode.com'});
request.end();
out = fs.createWriteStream('functionChecker.js');
request.on('response', function (response) {
response.setEncoding('utf8');
response.on('data', function (chunk) {
out.write(chunk);
});
});
//function name: stuff
//requires functions: false
//is defined: false
//description: blah blah woohoo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With