{"id":3091,"date":"2016-02-07T20:09:02","date_gmt":"2016-02-07T20:09:02","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=3091"},"modified":"2016-02-07T20:09:02","modified_gmt":"2016-02-07T20:09:02","slug":"fixing-error-output-is-not-a-tty-in-node","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/fixing-error-output-is-not-a-tty-in-node\/","title":{"rendered":"Fixing error: &#8220;output is not a tty&#8221; in Node"},"content":{"rendered":"<p>If you write a Node script the prints output to the screen, and try to pipe the output to a file, you can get an error:<\/p>\n<pre lang=\"bash\">\n$ node extract.js > ideas.csv\noutput is not a tty\n<\/pre>\n<p>In my case, I was trying to write out a CSV file:<\/p>\n<pre lang=\"javascript\">\nfor (var k = 0; k < all.length; k++) {\n  console.log(all[k]); \n}\n<\/pre>\n<p>The solution to this is to open the file directly and write to it:<\/p>\n<pre lang=\"javascript\">\nvar fs = require('fs');\nvar results = '';\n\nfor (var k = 0; k < all.length; k++) {\n  results += all[k] + \"\\n\";\n}\n\nfs.writeFile(\"ideas.csv\", results);\n<\/pre>\n<p>The reason this doesn't work as expected appears to be that 'git bash' is passing the command through to the Windows cmd shell, and not handling the output stream correctly. Writing directly to a file avoids the issue entirely.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you write a Node script the prints output to the screen, and try to pipe the output to a file, you can get an error: $ node extract.js > ideas.csv output is not a tty In my case, I was trying to write out a CSV file: for (var k = 0; k < &hellip; \n\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/fixing-error-output-is-not-a-tty-in-node\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Fixing error: &#8220;output is not a tty&#8221; in Node&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[9],"tags":[198,302,387],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3091"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=3091"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3091\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=3091"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=3091"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=3091"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}