Skip to content

Instantly share code, notes, and snippets.

@nkabrown
Last active December 8, 2023 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkabrown/330fad55546b16e7e2bbf06b870ec9f8 to your computer and use it in GitHub Desktop.
Save nkabrown/330fad55546b16e7e2bbf06b870ec9f8 to your computer and use it in GitHub Desktop.
Advent of Code Node/ESM starting template
// in package.json need to set type field to module { "type": "module" }
import { open } from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
// recreate Node globals for ESM modules
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
(async () => {
// open file from full path
const file = await (open(path.join(__dirname, './test-data.txt')));
for await (const line of file.readLines()) {
console.log(line);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment