1

I am trying to use jQuery in a node.js application. It seems easy enough according to Can I use jQuery with Node.js? but when I tried to run npm install jQuery jsdom htmlparser xmlhttprequest and simply npm install jQuery neither one seemed to work for me. Here is the full text of the error message I got:

    $ npm install jQuery jsdom htmlparser xmlhttprequest
npm http GET https://registry.npmjs.org/htmlparser
npm http GET https://registry.npmjs.org/jQuery
npm http GET https://registry.npmjs.org/xmlhttprequest
npm http GET https://registry.npmjs.org/jsdom
npm http 304 https://registry.npmjs.org/jsdom
npm http 304 https://registry.npmjs.org/htmlparser
npm http 304 https://registry.npmjs.org/xmlhttprequest
npm http 200 https://registry.npmjs.org/jQuery
npm http GET https://registry.npmjs.org/contextify
npm http GET https://registry.npmjs.org/cssom
npm http GET https://registry.npmjs.org/request
npm http 304 https://registry.npmjs.org/contextify
npm http 304 https://registry.npmjs.org/cssom
npm http 304 https://registry.npmjs.org/request
npm http GET https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/bindings

> [email protected] install /Users/nicmeiring/node_modules/jsdom/node_modules/contextify
> node-gyp rebuild

info it worked if it ends with ok 
spawn python [ '/Users/nicmeiring/.node-gyp/0.6.14/tools/gyp_addon',
  'binding.gyp',
  '-I/Users/nicmeiring/node_modules/jsdom/node_modules/contextify/build/config.gypi',
  '-f',
  'make' ]
ERR! Error: not found: make
    at F (/usr/local/lib/node_modules/npm/node_modules/which/which.js:43:28)
    at E (/usr/local/lib/node_modules/npm/node_modules/which/which.js:46:29)
    at Object.oncomplete (/usr/local/lib/node_modules/npm/node_modules/which/which.js:57:16)
ERR! not ok
npm WARN optional dependency failed, continuing [email protected]
[email protected] ./node_modules/xmlhttprequest 
[email protected] ./node_modules/jquery 
[email protected] ./node_modules/htmlparser 
[email protected] ./node_modules/jsdom 
├── [email protected]
└── [email protected]

In my node.js application file (app.js) I include the jquery module using var $ = require('jQuery), but, as expected, it returns an error when I try to use jQuery in my application. Any ideas what is causing the install to fail? Thanks

UPDATE: the jquery module successfully installed but when I try to run my app I am getting a new error. Here are the scripts:

app.js

   var express = require('express')
  , routes = require('./routes')
  , $ = require('jquery');

var app = module.exports = express.createServer();

// Configuration

app.configure(function(){
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(require('stylus').middleware({ src: __dirname + '/public' }));
  app.use(app.router);
  app.use(express.static(__dirname + '/public'));

});

app.configure('development', function(){
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('production', function(){
  app.use(express.errorHandler());
});

// Routes

app.get('/', routes.index);
app.get('/', routes.getData);

app.listen(4000);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);

and index.js

var $ = require('jquery');

exports.index = function(req, res){
  console.log("rendering index.html")
  res.render('layout', { title: 'Express' })
};


var link = "http://en.wikipedia.org/w/api.php?action=parse&format=json&callback=?"

exports.getData = $.ajax({
                      url: link,
                      dataType: JSON,
                      data: data,
                      success: function(data) {
                        console.log(data);
                        console.log(data.parse.text['*']);
                      }
});

and here is the error I am getting when I start up the app

    Nic-Meirings-MacBook-Pro:Wiki2 nicmeiring$ node app

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
ReferenceError: $ is not defined
    at Object.<anonymous> (/Users/nicmeiring/Sites/Wiki2/routes/index.js:16:19)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at Object.<anonymous> (/Users/nicmeiring/Sites/Wiki2/app.js:7:14)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
4
  • When you type "make" to console, what do you see? This works well on my Ubuntu with Node 0.6.14 Commented Apr 10, 2012 at 22:44
  • where should i be typing "make" Commented Apr 10, 2012 at 22:56
  • to the place you are typing npm install ... ? Commented Apr 10, 2012 at 22:57
  • Nic-Meirings-MacBook-Pro:~ nicmeiring$ make -bash: make: command not found Commented Apr 10, 2012 at 22:58

1 Answer 1

2

It seems you are missing "make" which comes with Developer Tools. Here is the related SO question:

https://stackoverflow.com/a/1470005/337504

Sign up to request clarification or add additional context in comments.

2 Comments

thanks. ill check that out. what exactly should i be downloading from developer.apple.com?
ok thanks ill look. would you mind checking out my updated code above?

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.