- Issue created by @aangel
- Status changed to Closed: won't fix
over 1 year ago 8:19pm 31 July 2023 - πΊπΈUnited States aangel
There appear to be two ways of doing this:
The first is to read then eval a file:
const fs = require('fs'); fs.readFile('myFile.js', 'utf8', function(err, data) { if (err) throw err; const codeToAppend = "\nconsole.log('Hello, World!');"; const newCode = data + codeToAppend; eval(newCode); });
The second is to make an module that contains just imports:
imports.js: import fs from 'fs'; import path from 'path'; import express from 'express'; export { fs, path, express }; New file: import { fs, path, express } from './imports.js';
But that doesn't seem to make things measurably (much) easier since all modules have to be named in the import anyway. Must as well just include the import line that specifies the path.
At this point, since I'm not seeing this as being very valuable, I'm closing it.