Latest in Snippets
Small, self-contained code snippets you can drop straight into a project — each one solving a single Node.js or JavaScript problem well.
Modern JavaScript features you can use in Node.js 26
A batch of genuinely useful JavaScript additions is now unflagged in Node.js 26: Set operations (union, intersection, difference), lazy iterator helpers, RegExp.escape, Promise.try, Array.fromAsync, and Float16Array. Here's each one with real, verified output.
Temporal: the modern way to handle dates in Node.js
JavaScript's broken Date object finally has a replacement. Temporal — Stage 4 in ES2026 and enabled by default in Node.js 26 — brings immutable date/time types, real time-zone support, and sane arithmetic. Here's how to use it, with examples and the polyfill for older environments.
How to format output of international phone number with JavaScript
JavaScript offers lots of NPM packages, and every day it keep counting! I'm here to help you find those that work.
TypeScript-friendly useSize from @react-hook/resize-observer.
Here's a version that is TypeScript-friendly... And not just that, it's a complete file you can put in your project and import from your components:
import useResizeObserver from "@react-hook/resize-observer" import { useLayoutEffect, useState } from "react" const useSize = (target:any) => { const [size, setSize] = useState<DOMRectReadOnly>() useLayoutEffect(() =>...Group in a group with TailwindCSS.
group classes. Imagine having a main menu dropdown group, where top level elements are groups, and sub-level elements are groups as well. You might be tempted to use something like this:<ul class="relative"> <li class="group"> Top level item <ul class="hidden group-hover:block"> <li class="group"> Sub level items will be here <ul class="hidden group-hover:block"> <li>Sub-sub level item 1</li> <li>Sub-sub level item 2</li> <li>Sub-sub level item 3</li> </ul> </li> </ul> </li> </ul> While...clearTimeout or clearInterval in React Native views with React Navigation
useFocusEffect to the rescue
useFocusEffect is a special hook from @react-navigation/native,...How to resize all JPGs in a folder to PNGs with a maximum width using FFmpeg?
This one command will get all JPGs in a folder, convert to PNGs and downscale it if it's more than 512px width:
for i in *.jpg; do ffmpeg -y -i "$i" -vf "scale='min(512,iw)':-1" -sws_flags bilinear "${i%.*}.png"; done How to convert all SVGs in a folder to PNG with Docker image?
Here's how I used it. First, I tried to run it against a single file to see if that works at all:
docker run --rm -v `pwd`:/svg burke/svg2png "Logo.svg" -w 256 Surely enough, it...error TS2792: Cannot find module 'moment'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
moment into a TypeScript React (.tsx) module?To fix the issue, you will need to adjust your
tsconfig.json file and add "moduleResolution": "node" to your compilerOptions, so it looks like this:{ "compilerOptions": { ... "moduleResolution": "node", ... } } The "moduleResolution": "node" setting in tsconfig.json tells the TypeScript compiler to use Node.js module resolution logic when resolving module names. This allows...Cannot augment module 'console' with value exports because it resolves to a non-module entity.
I got this with a Figma widget module
@figma/plugin-typings, and the solution was quite simple - add this to your .tsconfig.json:{ "compilerOptions": { ... "skipLibCheck": true, ... Et voilà!5 ways to create an HTTP/HTTP2 server with Node.js.
1. Using the built-in
http.createServer The easiest and most typical way is to use the built-in http module.const http...Prevent CSS column break within an element
columns rule and getting rid of all those JavaScript libraries. One of the elements got suddenly cut and wraps to the next column.Let's look at this simple example of CSS columns. First, the HTML:
<div class="columns"> <div>Item 1</div> <div>Item 2, which is slightly longer</div> <div>Item 3, which is also longer and jumps to next column</div> <div>Item 4</div> <div>Item 5</div> <div>Item 6</div> </div> ...