7

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?

4

1 Answer 1

4

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.