Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Unexpected token ) node js eval a functtion

Unexpected token ) node js eval a functtion

Problem

I am storing a function in my database and retrieving it from the database with node.js

When I console.log the column containing the function this is the output

(function(settings){var options = {host: 'somehost.com',path: 'some/path/' + settings.token + '?mobile=' + settings.number + '&message=' + settings.message};callback = (function(response) {var str = '';response.on('data', (function (chunk) {str += chunk;}));response.on('end', (function () {settings.result(str);})));}settings.httpRequest.request(options, callback).end();})

When I console.log typeof column it prints out string

But when I do

var func = eval(column);

It results in Unexpected token )

Does anyone know why?

I have made my function smaller now:

function(settings){var options = {host: 'api.smsmonster.co.za',path: '/uv1.svc/SendSMS/' + settings.token + '?mobile=' + settings.number + '&message=' + settings.message}settings.httpRequest.request(options, settings.callback).end();}
Problem courtesy of: Armand

Solution

(
function(settings){
 var options = 
  {
     host: 'somehost.com',
     path: 'some/path/' + settings.token + '?mobile=' + settings.number + '&message=' +        settings.message
  };
 callback = ( function(response) {
   var str = '';
   response.on('data', (function (chunk) {
    str += chunk;
    })
);
response.on('end', (function () {
  settings.result(str);
  })
  )
 /*{!here}*/);
} //
Solution courtesy of: ygaradon

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Unexpected token ) node js eval a functtion

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×