Node.js Snippets

The Node.js snippet collection contains JavaScript utilities for Node.js 18.x. It includes helper functions related to server-side code and filesystem operations, while general-purpose helpers can be found in the JavaScript snippet collection.

  • Create a static file server with Node.js

    Create your own static file server with Node.js in just 70 lines of code.

    JavaScript, Node · Jun 5, 2022

  • Introduction to the Node.js test module

    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 · Apr 30, 2023

  • Calculate SHA-256 hash (Node.js)

    Creates a hash for a value using the SHA-256 algorithm. Returns a promise.

    JavaScript, Node · Oct 13, 2021

  • Introduction to Semantic Versioning (SemVer)

    Learn how semantic versioning works and how to use it to correctly version your software.

    JavaScript, Node · Jul 16, 2023

  • Generate UUID (Node.js)

    Generates a UUID in Node.JS.

    JavaScript, Node · Mar 14, 2022

  • Stream is duplex

    Checks if the given argument is a duplex (readable and writable) stream.

    JavaScript, Node · Oct 20, 2020

  • Stream is writable

    Checks if the given argument is a writable stream.

    JavaScript, Node · Oct 20, 2020

  • Command-line arguments

    Gets the command-line arguments passed to a Node.js script.

    JavaScript, Node · Apr 26, 2022

  • Stream is readable

    Checks if the given argument is a readable stream.

    JavaScript, Node · Oct 20, 2020

  • Environment is Node.js

    Determines if the current runtime environment is Node.js.

    JavaScript, Node · Apr 2, 2021

  • JSON to file

    Writes a JSON object to a file.

    JavaScript, Node · Oct 20, 2020

  • Colorize text

    Adds special characters to text to print in color in the console (combined with console.log()).

    JavaScript, Node · Nov 3, 2020

  • Encode string to Base64

    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 · Sep 15, 2020

  • Read file lines

    Returns an array of lines from the specified file.

    JavaScript, Node · Oct 22, 2020

  • Value is stream

    Checks if the given argument is a stream.

    JavaScript, Node · Oct 20, 2020