Archives For node.js

When you’re developing web apps they tend to start out simple and then grow more and more complicated. On your servers you have services for your dependencies, but when you’re in development mode, it can be tricky to get everything running at the right time. The tool I’ll show you here works for Node.js, PHP, Java, Ruby, Python and more.

I use a laptop as my main computer and in order to save battery life, I limit the number of services I have running. A common app may be built with Node.js and rely on MongoDB and Redis. Therefore I launch MongoDB, launch Redis, then when all are running, launch my Node app. Then when I’m done I have to remember to shut each down. It’s a chore – exactly the kind of chore computers are great at, so let’s have the computer do it for us. Continue Reading…

It’s quite common to create an app where you want to protect numerous pages. It’s not difficult to check for req.user and force the user to a login page, but code duplication is not a good idea. Fortunately, it’s quite easy to write a middleware that will require authentication for a whole set or URLs.

First, we’ll set some assumptions: You’re using Express 4.x, you’re using router (is there any other way?) and you’re probably using Passport. I don’t think Passport is required for this solution, but it’s the only option I’ve tested with. Let’s assume that you’ve got a homepage that does not require authentication but the rest of your site, other than the login/logout/register pages, require authentication. Continue Reading…

Recently I built a demo application using Sails 10.x (currently in beta) and needed to add authentication support to it. One of the challenges with this is that the documentation for the beta Sails is not complete yet, and much has changed. The documentation is still great, so I definitely recommend making it your first stop.

While browsing through NPM modules I foundĀ sails-generate-auth which looked like an excellent solution for authentication. Yes, it works, but unfortunately the documentation is not written very well. The Github page makes it look like all you need is a configuration file and you’re set. In reality, there is a bit more work to do. Here are the steps I took. Continue Reading…