title: How to use jQuery autocomplete with Node.js
body: <p>I am trying to implement the jQuery autocomplete with a Node REST service but can't get it work.</p>
  <p>This my source code:</p>
  <p>Autocomplete:</p>
  <pre><code>$('#search').autocomplete({
          source: function (req, res) {
              $.ajax({
                  url: &quot;http://www.example.com:3000/autocomplete&quot;,
                  dataType: &quot;jsonp&quot;,
                  type: &quot;GET&quot;,
                  data: {
                      term: req.term 
                  },
                  success: function (data) {
                      res($.map(data.results, function (item) {
                          return {
                              label: item.id,
                              value: item.id
                          };
                      }));
                  },
                  error: function (xhr) {
                      alert(xhr.status + ' : ' + xhr.statusText);
                  }
              });
          }    
      });
  </code></pre>
  <p>Node service:</p>
  <pre><code>exports.find = function(req, res) {
  var b=req.params.term;
  console.log(b);
  db.collection('publication', function(err, collection) {
        collection.find({type:'pub',content: new RegExp(b, 'i') }).limit(5).toArray(function(err, items) {
                  res.jsonp(items);
              });
          });
  };
  </code></pre>
  <p><strong>b</strong> appears undefined in the console and the autocomplete does not work.</p>