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.
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=2024Choose 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.
node go.js nextThis 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/01For re-runs on changes, use node --watch days/01/index.js, or nodemon days/01 if you already have nodemon installed.
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.
| 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, []);