Mastodon

oooops.dev

DevOps is hard

Serializing and de-serializing ES6 class instances recursively — September 30, 2022

Serializing and de-serializing ES6 class instances recursively

We have all been warned not to use ES6 classes. Perhaps by our colleagues, or perhaps by the endless amount of scary blog posts that show up if you dare Google the subject. However, if you thought you had a use case for them you might have used them anyway (or perhaps you are in too deep and cannot rewrite your entire codebase). And now you stumbled upon this serialization problem and need to quickly find a solution that isn’t “just use TypeScript instead”.

The gist of it is: JavaScript is not a typed language, although sometimes it is pretending to be. When we make use of type-y features like classes and interfaces, some behaviors might occur that are be a bit puzzling if you are coming from, say, Java or Kotlin. One such behavior is how class instances get converted to and from JSON.

Or rather, how they don’t.

Continue reading
The same code with Callbacks vs Promises vs Async/Await — February 13, 2021

The same code with Callbacks vs Promises vs Async/Await

Sometimes in JavaScript to have to deal with different flavours of asynchronous code, so it is handy to be able to map back and forth between them.

Callback

Functions that do something asynchronously are typically implemented using the callback pattern, and their implementation might look like this:

const myAsyncFunction = (parameter, callback) => {
    const result = //do something async here...
    callback(result, error);
};
Continue reading
Super Quick Node.js HTTP Server — January 16, 2021