#Make a readFile function look nicer

2 messages · Page 1 of 1 (latest)

hallow cliff
#

use promises (as you were already told)

#
const fs = require('node:fs/promises');

async function parseLockfile(path) {
    const data = await fs.readFile(path, 'utf8');
    const [pid, port, token] = data.split(':');
    return { pid, port, token };
}

(async () => {
    const lockfile = await parseLockfile('');
    console.log(lockfile.pid);
})():