title: Execute function from String in node.js
body: <p>Is there a way to execute a function from String passed as a request parameter and return result in node.js ?
  Imagine a request which contains String:</p>
  
  <pre><code>"db.users.find()"
  </code></pre>
  
  <p>as a parameter</p>
  
  <p>If I knew I wanted to execute this statement I would do this:</p>
  
  <pre><code>db.collection('users', function(err, collection) {
      collection.find().toArray(function(err, items) {
          res.send(items);
      });
  });
  </code></pre>
  
  <p>What I want is something like a parser which would execute given statement and returned results.</p>
  
  <p>I tried like this:</p>
  
  <pre><code>exports.execStatement = function(req, res) {
  //var statemnet = req.params.statement;
    var statement = "collection.find().toArray(function(err, items) {
          res.send(items);});";
    db.collection('users', function(err, collection) {        
      eval(statement)
     });
  };
  </code></pre>
  
  <p>This code gives me error:</p>
  
  <pre><code>var statement = "collection.find().toArray(function(err, prdel) { ...
  SyntaxError: Unexpected token ILLEGAL
  </code></pre>
  
  <p>What is wrong ? Why can't I execute code stored in a String ? After this works I would like to figure out how to execute code which is passed as a parameter in request.</p>
  
  <p>Is this approach even possible ?</p>