Skip to content

Instantly share code, notes, and snippets.

@tausiq2003
Last active January 14, 2024 19:05
Show Gist options
  • Save tausiq2003/77c5ce26da3f2bea7510f9001e22700d to your computer and use it in GitHub Desktop.
Save tausiq2003/77c5ce26da3f2bea7510f9001e22700d to your computer and use it in GitHub Desktop.
This is only.js template, it creates dynamic pages without HTML and CSS files.
const express = require("express");
const { JSDOM } = require("jsdom");
const app = express();
const port = 6969;
app.use(express.static("assets"));
app.get("/", (req, res) => {
const dom = new JSDOM(`<!DOCTYPE html>`);
const doc = dom.window.document;
// Use doc instead of document
// Build here
// More building....
// ...
// ...
// Before using this install express and jsdom
// npm install -S express jsdom
res.writeHead(200, { "Content-Type": "text/html" });
res.end(dom.serialize());
});
app.listen(port, () => {
console.log(`onlyjs is available at ${port}`);
console.log(__dirname);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment