Code with Hugo

Node.js and JavaScript Guides

  • Home
  • Books
  • Node
  • Testing
  • JavaScript
  • More...
  • Search
  • About
  • Gear & Setup
Subscribe
#testing #jest #node #javascript #jest

Jest assert over single or specific argument/parameters with .toHaveBeenCalledWith and expect.anything()

With Jest it’s possible to assert of single or specific arguments/parameters of a mock function call with .toHaveBeenCalled/.toBeCalled and expect.anything(). The full example repository is at github.com/HugoDF/jest-specific-argument-assert, more specifically lines 17-66 i ...

  • Hugo Di Francesco
    Author
4 min read
#express #docker #javascript #node

An enterprise-style Node.js REST API setup with Docker Compose, Express and Postgres

The why and how of enterprise-style Node.js application. A setup that’s easy to test and extend using battle-hardened technologies like Express.js, Postgres and Docker Compose to run locally. Dive into the code on GitHub directly: github.com/HugoDF/express-postgres-starter. ...

  • Hugo Di Francesco
    Author
8 min read
#deployment #netlify #cdn #meta

Enable CDN (Cloudflare) caching for your Netlify site

This post goes through how to reduce the amount of static assets served through Netlify by leveraging a CDN (Content Delivery Network) like Cloudflare. This will reduce your Netlify bandwidth usage for cacheable assets. It will also mean that you’re following industry-accepted be ...

  • Hugo Di Francesco
    Author
4 min read
#docker #node #docker-compose #deployment

Docker Compose Local HTTPS with nginx or Caddy and mkcert

A solution to serve your Dockerized application on Docker Compose with TLS/SSL locally by leveraging a HTTPS reverse-proxy and mkcert. Examples with Caddy and nginx are at: github.com/HugoDF/docker-compose-local-https Table of contents: ...

  • Hugo Di Francesco
    Author
10 min read
#deployment #node #javascript #tooling #netlify #dokku

Deployment options: Netlify + Dokku on DigitalOcean or Hetzner Cloud vs now.sh, GitHub Pages, Heroku and AWS

Settling on a Netlify + Dokku on DigitalOcean (for US) or Hetzner Cloud (for EU) deployment stack for JavaScript and Node. Over the last few years I’ve never quite settled on a goto deployment strategy for my apps and projects. Technology-wise it has settled towards Vue or stati ...

  • Hugo Di Francesco
    Author
5 min read
#node #ava #Testing #javascript

JavaScript Object.defineProperty for a function: create mock object instances in Jest or AVA

This post goes through how to use Object.defineProperty to mock how constructors create methods, ie. non-enumerable properties that are functions. The gist of Object.defineProperty use with a function value boils down to: const obj = {} Object.defineProperty(obj, 'yes', { ...

  • Hugo Di Francesco
    Author
3 min read
#git #bash

Fix git “tip of your current branch is behind its remote counterpart” - 4 real-world solutions

When working with git a selection of GitLab, GitHub, BitBucket and rebase-trigger-happy colleagues/collaborators, it’s a rite of passage to see a message like the following: Pushing to [email protected]:some-project/some-repo.git To [email protected]:some-project/some-repo.git ! [rejec ...

  • Hugo Di Francesco
    Author
5 min read
#javascript #fetch

Pass cookies with axios or fetch requests

When sending requests from client-side JavaScript, by default cookies are not passed. By default, fetch won’t send or receive any cookies from the server, resulting in unauthenticated requests https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch Two JavaSc ...

  • Hugo Di Francesco
    Author
1 min read
#Express #node #jest #Testing #javascript

A testing guide for Express with request and response mocking/stubbing using Jest or sinon

To test an Express handler, it’s useful to know how to successfully mock/stub the request and response objects. The following examples will be written both using Jest and sinon (running in AVA). The rationale for this is the following. Jest is a very popular “all-in-one” testing ...

  • Hugo Di Francesco
    Author
17 min read
#Express #node #javascript #deployment

Node.js configuration management without config or dotenv

The config npm package is great (npmjs.com/package/config), but it encourages confusing and non-12-factor-app-compliant patterns. We’ll look at some of the patterns it encourages and why they’ll bring you struggles down the road as well a simple, single-file, no-dependency way to ...

  • Hugo Di Francesco
    Author
3 min read
← Next Posts Page 9 of 15  Previous Posts →

Interested in Alpine.js?

Power up your debugging with the Alpine.js Devtools Extension for Chrome and Firefox. Trusted by over 15,000 developers (rated 4.5 ⭐️).

Install Now close
Code with Hugo
Latest Posts Github