Start of main content
Convert to absolute path
JavaScript, Node.js, String · Oct 22, 2020

Converts a tilde path to an absolute path.
- Use
String.prototype.replace()
with a regular expression and os.homedir()
to replace the ~
in the start of the path with the home directory.
import { homedir } from 'os';
const untildify = str => str.replace(/^~($|\/|\\)/, `${homedir()}$1`);
untildify('~/node');
More like this

Master string manipulation in JavaScript with this ES6 snippet collection.
Collection · 107 snippets

Creates a base-64 encoded ASCII string from a String object in which each character in the string is treated as a byte of binary data.
JavaScript, Node.js · Sep 15, 2020

The Node.js test module is a new testing tool that's still in its early stages. Learn more about it in this short introduction.
JavaScript, Node.js · Apr 30, 2023

Learn how semantic versioning works and how to use it to correctly version your software.
JavaScript, Node.js · Jul 16, 2023