#node #Express #javascriptRead and parse POST/PATCH/PUT request JSON or form body with Express and no dependenciesWhen asked to handle data in a request body, developers who have used Express (the “Fast, unopinionated, minimalist web framework for Node.js”) before, reach for the body-parser library. What they might not know is that body-parser is a dependency of Express and its main JSON par ...
#node #javascript #Sequelize #productivityUsing ES6 classes for Sequelize 4 or 5 modelsThe ES2015 or ES6 specification introduced class to JavaScript. Libraries like React went from React.createClass to class MyComponent extends React.Component, ie went from rolling their own constructor to leveraging a language built-in to convey the programmer’s intent. For a Nod ...
#testing #jest #node #javascript #jestJest 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 ...
#express #docker #javascript #nodeAn enterprise-style Node.js REST API setup with Docker Compose, Express and PostgresThe 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. ...
#docker #node #docker-compose #deploymentDocker Compose Local HTTPS with nginx or Caddy and mkcertA 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: ...
#deployment #node #javascript #tooling #netlify #dokkuDeployment options: Netlify + Dokku on DigitalOcean or Hetzner Cloud vs now.sh, GitHub Pages, Heroku and AWSSettling 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 ...
#node #ava #Testing #javascriptJavaScript Object.defineProperty for a function: create mock object instances in Jest or AVAThis 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', { ...
#Express #node #jest #Testing #javascriptA testing guide for Express with request and response mocking/stubbing using Jest or sinonTo 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 ...
#Express #node #javascript #deploymentNode.js configuration management without config or dotenvThe 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 ...
#javascript #nodeAsync JavaScript: history, patterns and gotchasA look at the history, patterns and gotchas of asynchronous operations in JavaScript. We’ll go through the pros and cons of callbacks, Promises and async/await. Present some pitfalls to bear in mind as well as introducing how you would deal with certain situations. Live-cod ...