Go-style normalized errors in JS

Usage no npm install needed!

<script type="module">
  import resn from '';



Go-style normalized errors in JS

GitHub | NPM


npm i resn
const resn = require('resn')


Here, we pass in a callback function (fs.readFile) to be converted to a resn callable.

const rReadFile = resn(fs.readFile)

;(async () => {
    var {err, res} = await rReadFile('index.js')

    if (err) {
        console.error('[!]', err.message)

    console.log('[~] Read file!')

We can pass in all kinds of things to make resn callables. We can convert almost all libraries' functions, new and old, to resn callables.

const myPromFunc = () => {
    return new Promise((res, rej) => {

const rPromFunc = resn(myPromFunc)

const basicFunc = function (giveError = false) {
    if (giveError) {
        throw new Error('Failed!')

    return 'Hey!'

const rBasicFunc = resn(basicFunc)

We can even convert a whole library of varying-style functions to resn callables at once.

const fs = resn(require('fs'))

;(async () => {
    var {err, res} = await fs.readFile(__filename)

    // ...


The resn method of handling errors is effective because it avoids problems associated with old style handling. We can avoid using try/catch constantly and can gracefully handle all errors. Also, we can convert all kinds of functions into a common format easily with one function.

It is recommended that you use var when receiving resn callable responses as this will allow you to reuse the err and res variable names within a scope.