Last active
December 8, 2023 17:39
-
-
Save nkabrown/330fad55546b16e7e2bbf06b870ec9f8 to your computer and use it in GitHub Desktop.
Advent of Code Node/ESM starting template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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