{"id":3296,"date":"2014-03-21T20:23:29","date_gmt":"2014-03-21T20:23:29","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/21\/node-jsrelated-issues-collection-of-common-programming-errors\/"},"modified":"2014-03-21T20:23:29","modified_gmt":"2014-03-21T20:23:29","slug":"node-jsrelated-issues-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/21\/node-jsrelated-issues-collection-of-common-programming-errors\/","title":{"rendered":"node.jsRelated issues-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/2f90e858672c079741471f72cba5480c?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nBen<br \/>\njavascript json node.js object asynchronous<br \/>\nI am new to Node and struggling to access a simple JSON object. My request.body will have JSON content similar to the following:{&#8220;store_config&#8221;: [{&#8220;name&#8221;: &#8220;hello&#8221;,&#8221;name2&#8243;: &#8220;world&#8221;}] }The &#8220;store_config&#8221; value will always be present, however the keys and values within could be anything.How can I iterate through the keys and values to access each? I would also like to process each in an asynchronous manner.Appreciate any thoughts or direction.UPDATEconsole.log(typeof(request.body));Returns: Objectp<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/26e6b2d733085422446dac60a2027973?s=32&amp;d=identicon&amp;r=PG&amp;f=1\" \/><br \/>\nerythraios<br \/>\njavascript ajax node.js<br \/>\nI have an object containing a date object. When I post it to a NodeJS server, it&#8217;s still an object but the time has been converted to a string. Is there any way to avoid this? I can&#8217;t parse the entire object because I get an &#8220;Unexpected token o&#8221; error (I assume because it&#8217;s still an object). Before:Object {title: &#8221; &#8211; fd&#8221;, start: Tue Feb 11 2014 09:00:00 GMT-0500 (EST), end: Tue Feb 11 2014 10:00:00 GMT-0500 (EST), allDay: false, id: &#8220;&#8221;.}After: Object allDay: &#8220;false&#8221; end: &#8220;Tue Feb 11 2014 10:00:0<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/0e79ab836fcb94adfbd500e8d4bef181?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nFaran<br \/>\nnode.js global-variables user-agent sails.js controllers<br \/>\nI am trying to have a variable which can be accessible by all controllers in my node project. Currently in one controller I have:var ua = req.headers[&#8216;user-agent&#8217;];var isMobile = &#8220;no&#8221;;if(\/mobile\/i.test(ua))isMobile=&#8221;yes&#8221;;It&#8217;s pointless to copy past all of this for all my controllers and pass the isMobile variable to the view. I&#8217;d like to get the value of isMobile set once, and then pass it wherever I want from my controllers.Is there an easy way to do this rather than have those 4 lines of code<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/aaf8fbc1f880479454378a6663199bfa?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nKevin Bradshaw<br \/>\nnode.js ubuntu-12.04<br \/>\nI have just installed node.js on my ubuntu laptop.I followed the instructions found here: http:\/\/davidtsadler.com\/archives\/2012\/05\/06\/installing-node-js-on-ubuntu\/#application and installed from the git repositoryInstalled with no errors, but when I ran the server.js sample application program nothing happened. Worse still, I tried to run a ver basic hello world script called hello.jsconsole.log(&#8220;hello world&#8221;);When I type : node hello.jsnothing happens, there is no error message, nothing is writ<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/3d3d7d9838d57e9c11767686542a6489?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nTarion<br \/>\nnode.js angularjs express jade mixins<br \/>\nRelated to that question: Jade Mixins in AngularJSI have the following (simplified) code:tr(ng-repeat=&#8221;avatar in avatars&#8221;)+avatarRow({name: &#8216;{{avatar.name}}&#8217;})mixin avatarRow(avatar)td avatar.nameSince it is a bit dirty to resolve the &#8220;avatar&#8221; object before it is passed to the mixin I would prefer a more angular like solution.Still it would be cool, to keep the mixin code in the same file, but thats not a must. As far as I see, with ngInclude I can no pass any args. So how to handle that?Continu<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/16d6dc87aba94c20445db2f7567bd8ba?s=32&amp;d=identicon&amp;r=PG&amp;f=1\" \/><br \/>\ngelly<br \/>\nnode.js angularjs socket.io localhost<br \/>\nI&#8217;m using an AngularJs, node &amp; socket.io to write an app where I want to have some shared data in my different clients. I&#8217;m looking at this example: https:\/\/github.com\/mhevery\/angular-node-socketioI get everything up and running and it works fine if I go to the location of my index.html in my file system (c:\/user\/angularnodesocket\/index.html), but when I go to localhost:8888 the site still shows but the angular stuff is not interpretated.I get this error on localhostResource interpreted as S<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/8d743c1f96b372a37ca5edc4fd9b6135?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nAli<br \/>\njavascript jquery node.js<br \/>\nI&#8217;m getting Uncaught SyntaxError: Unexpected token ILLEGAL And I checked that because of thiscurrentMd: &#8216;&lt;div&gt;#hehe&lt;\/div&gt;&#8217;The two extra new line that is in the currentMd breaking it, so how can I instead replacing that new lines with \\n ??So it will be like this insteadcurrentMd: &#8216;&lt;div&gt;#hehe\\n\\n&lt;\/div&gt;&#8217;In javascript or jQuery would be fine.It may be not clear that the content is actually just an example here.The actual content is being retrieved from a database, so in the<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/784a570374d05695178c2617b3f1b550?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nfancy<br \/>\njavascript json node.js npm<br \/>\nWhat could be wrong here?\/opt\/local\/lib\/node\/.npm\/embedly\/0.3.2\/package\/package.json:1 &#8220;name&#8221;: &#8220;embedly^node.js:134throw e; \/\/ process.nextTick error, or &#8216;error&#8217; event on first tick^ 13 Apr 02:23:06 &#8211; [ERROR] SyntaxError SyntaxError: Unexpected token :package.json{ &#8220;name&#8221;: &#8220;embedly&#8221; , &#8220;version&#8221;: &#8220;0.3.2&#8221; , &#8220;description&#8221;: &#8220;Embedly client library for node&#8221; , &#8220;homepage&#8221;: &#8220;https:\/\/github.com\/embedly\/embedly-node&#8221; , &#8220;keywords&#8221;: [] , &#8220;author&#8221;:{ &#8220;name&#8221;: &#8220;Bob Corsaro&#8221;, &#8220;email&#8221;: &#8220;bob@embed.ly&#8221;, &#8220;url&#8221;: &#8220;ht<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/9f33372607e75d88ca79e7ddcd88e14f?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJorge Aranda<br \/>\nnode.js express jade<br \/>\nI have a Jade template with lines like these:htmlheadtitle Person Detailsscriptvar Person = function () {this.name = &#8220;#{person.name}&#8221;,this.contactInfo = &#8220;#{person.contactInfo}&#8221;} &#8230;When I render this template I pass it a person object.The problem is that some of the fields I pass to the template (such as person.contactInfo above) may have newline characters, and the rendering process outputs something like this:&lt;html&gt;&lt;head&gt;&lt;title&gt;Person Details&lt;\/title&gt;&lt;script&gt;var Pe<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/SZ9em.jpg?s=32&amp;g=1\" \/><br \/>\nopcode<br \/>\nmysql database node.js scaling multi-master-replication<br \/>\nI am creating this web application in Node.js and MySQL and I am struggling on data synchronisation. Here&#8217;s the scenario:Suppose we have 1000 customers that all have a local webserver-database in their office\/site. A user can login, edit data, datalog sensors, etc. All these activities contribute to, for the sake of the example, around 500KB of table data per day, per customer\/site. So each of the 1000 customers have a local database that will always constantly get updated with new data many tim<\/li>\n<\/ul>\n<p>Web site is in building<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ben javascript json node.js object asynchronous I am new to Node and struggling to access a simple JSON object. My request.body will have JSON content similar to the following:{&#8220;store_config&#8221;: [{&#8220;name&#8221;: &#8220;hello&#8221;,&#8221;name2&#8243;: &#8220;world&#8221;}] }The &#8220;store_config&#8221; value will always be present, however the keys and values within could be anything.How can I iterate through the keys and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3296","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3296","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3296"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3296\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3296"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3296"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}