javascript - String compare with node.js -


i doing project using tessel read text file on server , perform function based upon value. new node.js, , have managed of items running, having issue getting comparison work.

i know reading value (which either "1" or "0") fine because when incorporate console.log(//variable) in code, console shows value.

the basic code have been playing is:

var http = require('http');  setinterval(function() { var options = {   host: 'www.users.wfleitz.com',   path: '/fleitzwc/example.txt' };  callback = function(response) {   var str = '';    response.on('data', function (chunk) {     str += chunk;   });    response.on('end', function () {     console.log(str)      if (str == "1"){       console.log("it reads fine ")   }        });  } http.request(options, callback).end();  }, 1000); 

i have tried moving "if" statement around, , wording "if" statement:

if (str.tostring == "1"){           console.log("it reads fine ")       } 

could tell me if placement, or syntax issue? or if off base together? thinking may issue although file should have "1" or "0" in it, have had instances needed trim file contents ensure getting 1 value, can't find way in node.js.

thank in advance, wfleitz

you need call tostring() function so:

if (str.tostring() == "1") {   // note ------^^ parens call function.   console.log("it reads fine ") } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -