Let’s Code It: Static Site Generator with Rx.js

Last post, we went over building a Static Site Generator (SSG) in Node.js. We used Promises for flow control, and that worked for reading each Markdown input file, transforming it into HTML, and writing that to disk, once per file. What if instead of running this build process once per input file, we want it to run once per input file every time that input file is created or changed?

If our goal is to map a sequence of events over time (file creation or modification) to one or more operations (building Markdown to HTML and writing to disk), it’s very likely Observables are a good fit! In this blog post, we’ll look at how to use Observables and RX.js to create a SSG with built-in, incremental watch rebuilds, and with with multiple output streams (individual posts and blog index page).
Read more

Let’s Code It: Static Site Generator

Traditionally, if you wanted to create a blog or website that you can update easily without having to directly edit HTML, you’d use a tool like WordPress. The basic flow for serving a website from a CMS like WordPress is as follows:

  1. Store content (e.g. “posts”) in a database
  2. Store display configuration (templates, CSS, etc.) separately
  3. When a visitor requests a page, run a script to…
    1. Pull the content from the database
    2. Read the appropriate template
    3. Put them together to build page HTML
    4. Send HTML to the user

Read more

Working with LoopBack Authentication and Authorization

One of LoopBack’s core features is the ability to lock down access to your APIs and define exactly who can do what with your data. LoopBack provides multiple tools to make this easy, but it’s helpful to see a real (although simple) application demonstrating the complete process of securing your APIs.

In this post I’ll demonstrate how to:

* Add support for users to your application.
* Add user registration and login/logout.
* Create rules for your API that follow common patterns, for example, only a logged in user can create content and only the owner of content can modify it.
Read more

Working with File Storage and LoopBack

I’ve got a confession to make: I absolutely love LoopBack. How much do I love it? Before I even joined the StrongLoop team at IBM I was blogging on LoopBack and giving presentations on it as well. I basically told the person interviewing me that it didn’t really matter if they hired me or not; I was going to evangelize LoopBack because I thought it was the coolest thing since sliced bread and beer. In general, I love LoopBack and every aspect of it. However, it doesn’t mean that it is perfect. Today I’m going to discuss a feature that is—in my opinion—somewhat “rough”. I’m not saying to avoid it, not at all, just be prepared for a somewhat bumpy ride. Ready?

So, one of the things that LoopBack makes incredibly easy is handling data in a persistence system. You define a model, let’s say Cat, various properties and types, and then LoopBack can handle persisting that in a variety of different storage mechanisms, from Oracle to MySQL to MongoDB. It just plain works, which is cool. However, the data we’re typically dealing with are simple strings represented in JSON. What about binary data?
Read more

Interactive Debugging with Node.js

A “step-through debugger” (also called an “interactive debugger” or just “debugger”) is a powerful tool that can be very handy when your application isn’t behaving the way you expect. You can use it to pause your application’s code execution to:

  • Inspect or alter application state.
  • See the code execution path (“call stack”) that leads to the currently-executing line of code.
  • Inspect the application state at earlier points on the code execution path.

Interactive debuggers* are familiar to every Java developer (among others), but they are less well known in the JavaScript world. This is unfortunate, both because debuggers can help  diagnose logic issues, and because the JavaScript debugging tools today are the best and easiest to use they’ve ever been! This post will introduce the Node.js debugging tools in Visual Studio Code (VS Code) for programmers who have never used a debugger before. Read more