Skip to content

Instantly share code, notes, and snippets.

😇
Living the JS life

Vladimir de Turckheim vdeturckheim

😇
Living the JS life
View GitHub Profile
View ALS.md

AsyncLocalStorage API

The AsyncLocalStorage class has been introduced in the Async Hooks module.

This API allows keeping a context across asynchronous operations. For instance, if an sequence id is stored within an instance of AsyncLocalStorage for each entering HTTP requests in a server, it will be possible to retrieve this id without knowing the current HTTP request.

const http = require('http');
View fastr.js
'use strict';
const run = function (getStack) {
process.nextTick(() => {
process.nextTick(() => {
process.nextTick(() => {
process.nextTick(() => {
process.nextTick(() => {
process.nextTick(() => {
console.log(getStack());
})
View comparing_async_local_context.md

DISCLAIMER: This was a working document now availabe in https://github.com/nodejs/TSC/issues/807. No comments on the current gist will be accepted

Executive summary: Introducing a CLS-like API to Node.js core

Context: the 3 PRs and 1 consensus

On the TSC meeting of 2020-JAN-22, the TSC reached consensus regarding the need to have an Asynchronous Storage API in core.

View async_storage.md

Most Node.js framework requires to pass an object representing the current HTTP request through every layers of the application. This is most visible in Expressjs-based applications:

// TODO middleware example

Other frameworks, will create an wrapping object around the raw Node.js request:

// TODO hapi link

But at the end of the day, developers end up passing bloated objects representing the requests through their codebase:

View README.md

MongoDB need to be installed and running on localhost (otherwise, edit the value of MONGO_URL in server.js).

For Sqreen to work, create a new application on https://my.sqreen.io and add the sqreen.json file to the root of the project.

Start the server with node server.js

Perform an attack with:

$ curl -X POST \
  http://localhost:3000/login \
View beyond_domains.md

Beyond Domains

Goal

The goal of this document is to analysis the content of the Domain Module Postmortem to define the need for either:

  • a new internal API in Node.js core (SOLUTION 1)
  • a solution to update domain API to have TSC reconsider its deprecation status (SOLUTION 2)
  • an external API to replace domain only in userland (SOLUTION 3)
View keybase.md

Keybase proof

I hereby claim:

  • I am vdeturckheim on github.
  • I am ecares (https://keybase.io/ecares) on keybase.
  • I have a public key ASCYrvfvzp9hRv0VSx6JA_pAUKwnqVsiHgwUuRi-V-HMvQo

To claim this, I am signing this object:

View test.js
'use strict';
const Code = require('code');
const expect = Code.expect;
const Lab = require('lab');
const lab = module.exports.exports.lab = Lab.script();
const after = lab.after;
const before = lab.before;
const describe = lab.describe;
const it = lab.it;
View app.post.js
app.post('/posts', Celebrate.celebrate(
{
body: Joi.object().keys({
title: Joi.string().required(),
content: Joi.string().required()
})
}
),
(req, res, next) => {
View server.js
'use strict';
const Express = require('express');
const BP = require('body-parser');
const DB = require('./db.js');
const app = Express();
app.use(BP.json());
You can’t perform that action at this time.