1. Docs
  2. Stack

Modern LIFO entry

When the newest work goes first.

js-queue/stack exposes easy-stack 2.1.0 for last-in-first-out execution with the same Node 22.13 baseline.

Load it explicitly

The stack stays a separate contract.

The queue core is FIFO. Import the stack entry only when the most recently added task should execute first.

ESM

Native import

import Stack from 'js-queue/stack';
CommonJS

Conditional require

const Stack=require('js-queue/stack.js');
const stack=new Stack;
stack.autoRun=false;

stack.add(first,second,third);
stack.next(); // third runs first

Choose the order

FIFO and LIFO solve different problems.

Both structures use explicit next() hand-offs, but they remove pending work from opposite ends.

Queue versus stack
PropertyQueueStack
OrderFirst in, first outLast in, first out
Entryjs-queuejs-queue/stack
RemovesFront via array shiftBack via array pop
Best fitRequests, messages, ordered pipelinesUndo-like work, nested traversal, newest-first priority
State surfacecontents, size, runningstack, contents(), size, running
The stack follows the modernized upstream contract.

easy-stack 2.1.0 uses private instance fields and one shared Node module for native ESM and CommonJS while preserving its public flow contract. See the focused easy-stack documentation for its complete API and benchmark.

Need predictable arrival order instead?

Start with Queue