Note that there are some explanatory texts on larger screens.

plurals
  1. PONode JS Error: ENOENT
    text
    copied!<p>I'm following along with: <a href="http://www.nodebeginner.org/#serving-something-useful" rel="noreferrer">The Node Beginner Book</a></p> <p>After testing with the code from another SO post:</p> <pre><code>var Fs = require('fs'); var dirs = ['tmp']; var index; var stats; for (index = 0; index &lt; dirs.length; ++index) { try { stats = Fs.lstatSync(dirs[index]); console.log(dirs[index] + ": is a directory? " + stats.isDirectory()); } catch (e) { console.log(dirs[index] + ": " + e); } } </code></pre> <p>The error persist:</p> <blockquote> <p>Error: ENOENT, no such file or directory 'tmp'</p> </blockquote> <p><img src="https://i.stack.imgur.com/RnBbE.png" alt="app dir structure"></p> <p>The permissions on tmp are 777.</p> <p><strong>requestHandlers.js</strong></p> <pre><code>var querystring = require("querystring"), fs = require("fs"); function start(response, postData) { console.log("Request handler 'start' was called."); var body = '&lt;html&gt;'+ '&lt;head&gt;'+ '&lt;meta http-equiv="Content-Type" '+ 'content="text/html; charset=UTF-8" /&gt;'+ '&lt;style&gt;input{display: block; margin: 1em 0;}&lt;/style&gt;'+ '&lt;/head&gt;'+ '&lt;body&gt;'+ '&lt;form action="/upload" method="post"&gt;'+ '&lt;textarea name="text" rows="20" cols="60"&gt;&lt;/textarea&gt;'+ '&lt;input type="submit" value="Submit text" /&gt;'+ '&lt;/form&gt;'+ '&lt;/body&gt;'+ '&lt;/html&gt;'; response.writeHead(200, {"Content-Type": "text/html"}); response.write(body); response.end(); } function upload(response, postData) { console.log("Request handler 'upload' was called."); response.writeHead(200, {"Content-Type": "text/plain"}); response.write("You've sent the text: "+ querystring.parse(postData).text); response.end(); } function show(response, postData) { console.log("Request handler 'show' was called."); fs.readFile("/tmp/test.jpg", "binary", function(error, file) { if(error) { response.writeHead(500, {"Content-Type": "text/plain"}); response.write(error + "\n"); response.end(); } else { response.writeHead(200, {"Content-Type": "image/jpg"}); response.write(file, "binary"); response.end(); } }); } exports.start = start; exports.upload = upload; exports.show = show; </code></pre> <p><strong>Index.js</strong></p> <pre><code>var server = require("./server"); var router = require("./router"); var requestHandlers = require("./requestHandlers"); var handle = {} handle["/"] = requestHandlers.start; handle["/start"] = requestHandlers.start; handle["/upload"] = requestHandlers.upload; handle["/show"] = requestHandlers.show; server.start(router.route, handle); </code></pre> <p>A little stumped, any help appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload