title: Understanding how to use NodeJS to create a simple backend
body: <p>I have been trying to develop a rather simple server in nodejs. Basically, what I am going for is a simple API that requires authentication (simple username/password style). What I do <em>not</em> need is any kind of frontend functionality (templating etc.). My problem is, I can't seem to get my head around the approach of express/node.<br><br>
  Specifically, my questions are:</p>
  
  <ul>
  <li>How do I wire in the authentication? Do I pass several handlers into every route that requires authentication, or is there a more elegant way to do this?</li>
  <li>How does the Express middleware (like <code>app.use(express.bodyParser())</code>) work? Do they alter contents of the <code>request</code> or <code>response</code> object? Specifically, if I use the body parser (internally formidable?), where do I access the request data this is supposed to parse?</li>
  <li>When using authentication and I have, say, credentials stored in a database with more information about the individual client associated, at what point do I extract that information? I.e., when a user logs in, do I fetch the user record on login and pass it on, or do I fetch it in every handler that requires the information?</li>
  <li>Ultimately, do you know of an open source application that I could take a look at? I'd like to see something that has simple authentication and maybe even utilizes formidable, since uploading a file is one of my requirements.</li>
  </ul>
  
  <p>As I mentioned earlier, I believe my problem is ultimately a difficulty with the function-oriented approach in node (also, I have rather limited experience in webservice programming). If you know a resource where I could read up on how to approach architecting a nodejs app, please don't hesitate to point me to it.</p>