#JavaScript #Sequelize #testing #Node

Unit Testing Sequelize 4 ES6 class models

In “Using ES6 classes for Sequelize 4 models” we explored how to define Sequelize models using ES6 classes. One of the benefits of such an approach is that it allows easy unit testing, it allows you to instantiate the model without the baggage of all of Sequelize (and/or a database). The examples will use Jest module auto-mocking but should be portable to other module mocking libraries (eg. Proxyquire) with some modifications. ...

  • Hugo Di Francesco
    Author
2 min read
#JavaScript #Node #tooling #deployment

Build and deploy a Vue/React/Vanilla JS app with Parcel and GitHub pages

Parcel allows us to bundle frontend applications with no configuration and GitHub pages affords us a way to deploy them for free. Here’s how to use these two tools together to deploy a JavaScript application. Full example of a repo deployed like this: https://github.com/HugoDF/js-graphql-client-example, and see https://codewithhugo.com/js-graphql-client-example/. Or the repo with the demos: https://github.com/HugoDF/parcel-gh-pages-deploy and see https://codewithhugo.com/parcel-gh-pages-deploy/. ...

  • Hugo Di Francesco
    Author
2 min read
#JavaScript #Node #Docker #redis

Bring Redux to your queue logic: an Express setup with ES6 and bull queue

There always comes a point in a web application’s life where an operation is best served in the background, this is where queues come in. There are a few queuing solutions in Node. None of them are ridiculously dominant, eg. Kue, RSMQ, Bee Queue, bull. The issue with Kue, RSMQ and Bee Queue was its use of a done callback as the recommended API. Bull https://github.com/OptimalBits/bull is a premium Queue package for handling jobs and messages in NodeJS. It’s backed by Redis and is pretty feature-rich. Most of all, it leverages a Promise-based processing API which means async/await. We’ll walk through an application that sends webhooks with a given payload to a set of URLs. ...

  • Hugo Di Francesco
    Author
11 min read
#JavaScript #Node

ES6 by example: a module/CLI to wait for Postgres in docker-compose

When using docker-compose, it’s good practice to make anything that relies on Postgres wait for it to be up before launching. This avoids connection issues inside the app. This post walks through how to deliver this functionality both as a CLI and a module that works both as a CommonJS module (require) and ES modules, without transpilation. “A fast, production ready, zero-dependency ES module loader for Node 6+!” is esm’s promise. From this sample project, it’s worked. ...

  • Hugo Di Francesco
    Author
9 min read
#JavaScript #Node #Testing

Testing an Express app with SuperTest, moxios and Jest

Testing is a crucial part of the software development process. It helps to catch bugs, avoid regressions and to document the behaviour of a piece of software. Express is one of the most widespread libraries for building backend applications in JavaScript. What follows is a summary of how to set up an efficient unit testing strategy for such an application as well as a couple of situations you may be faced with when attempting to test. ...

  • Hugo Di Francesco
    Author
6 min read
#JavaScript #Node #CLI

How to make beautiful, simple CLI apps with Node

Channel your inner Sindre Sohrus and ship a beautifully simple CLI app using Node. Command line apps are a neat way to package repetitive tasks. This will walk you through some tools that are useful to build CLI apps. The idea 💡 Piping to the command line 🚇 Dealing with sequential actions ✨ Executable JavaScript files 🦅 Adding package binaries 📦 Publishing to npm 🚀 The idea 💡 When merging/rebasing, the file that always seems to cause trouble is the package-lock. ...

  • Hugo Di Francesco
    Author
3 min read
#JavaScript #Node #Docker #redis

Setting up Express and Redis with Docker compose

Redis and Express are tools that provide a simple and clean approach to their problem domains. The repo is available at: https://github.com/HugoDF/express-redis-docker. Redis is “an open source, in-memory data structure store, used as a database, cache and message broker”. It’s as simple and unopinionated as a database as it gets, it’s known for its performance and simplicity as a key-value store. It has great flexibility and can also be used as a message queue, circular buffer (and pretty much anything else a developer can come up with short of a relational database). ...

  • Hugo Di Francesco
    Author
4 min read