Skip to content
Public template

About

A Node.js starter for Advent of Code: input downloads, daily templates, and timed puzzle runners.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advent Toolkit — project illustration

Advent of Code · Starter

Download the input. Write the solution. Run both parts.

JavaScript: Node.js workflow: Advent of Code

Setup · Workflow · Utilities


A small CommonJS starter for solving Advent of Code puzzles. It creates a directory for each day, downloads your input, and provides a wrapper that times both parts.

Setup

Use a Node.js version with built-in fetch and --env-file support. The convenience command opens files with VS Code, so code must be available on your PATH.

git clone https://github.com/pagyew/AoC-template.git
cd AoC-template

Create .env in the repository root:

AOC_SESSION=YOUR_SESSION_COOKIE
AOC_YEAR=2024

Choose the year you want to solve. AOC_SESSION is the session-cookie value only, without the session= prefix. Keep it private; .env and puzzle input files are gitignored. No npm install step is required for the included helpers.

Daily workflow

node go.js next

This creates the next day after the highest existing day, downloads its input, copies the templates, and opens solve.js in VS Code. A fresh checkout starts with Day 1.

days/01/
├── 01.txt      # Your puzzle input
├── index.js    # Input reader and timing wrapper
└── solve.js    # Your implementation

Implement the exported function in solve.js:

module.exports = function ({ inputs, rawInput, isPart1, isPart2 }) {
  // inputs: input split into lines
  // rawInput: trimmed input as one string
  // isPart1 / isPart2: which puzzle part is running
  return 0;
};

Run the day from the repository root:

node days/01

For re-runs on changes, use node --watch days/01/index.js, or nodemon days/01 if you already have nodemon installed.

Reopening a day

node go.js last is intended to reopen the latest day. The current helper checks for NN/ before creating days/NN/, so an existing day can cause EEXIST. Open days/NN/solve.js directly to continue working. Input downloads also need a valid session and an unlocked puzzle.

Utilities

Utility Use
heap.js Priority queue for search and scheduling problems
nerdamer Bundled equation-solving tools from Nerdamer
solve-template.js The function copied into each new day
wrapper-template.js Input parsing, answers, and timing
const Heap = require("../../utils/heap");
const nerdamer = require("../../utils/nerdamer");

const queue = new Heap((a, b) => a - b, []);

About

A Node.js starter for Advent of Code: input downloads, daily templates, and timed puzzle runners.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Contributors

Languages