Skip to content

Instantly share code, notes, and snippets.

View Belrestro's full-sized avatar
🇺🇦

Andrew Vorobiov Belrestro

🇺🇦
  • Kyiv
View GitHub Profile
@Belrestro
Belrestro / static.mjs
Last active April 29, 2024 20:53
Simplest Static metatech
import path from 'node:path';
import fs from 'node:fs';
import http from 'node:http';
const HTTP_PORT = 3000;
const STATIC_DIR = path.join(process.cwd(), './static');
const fsExists = (filePath) => fs.promises.access(filePath).then(() => true, () => false);
const path = require('node:path');
const fs = require('node:fs');
const assert = require('node:assert');
const requireImpl = (pth) => {
assert((typeof pth) === 'string');
let moduleText;
const modulePath = path.join(process.cwd(), pth);
try {
moduleText = fs.readFileSync(modulePath);