How would I edit HTML files in NodeJS?

Viewed 42

Background

I am developing a game and I need to have the least possible requests sent to the server, I am making my own file bundler so I can combine separate files like index.html, index.js, and styles.css into a single HTML file where the js would be loaded in the head of index.html inside of script tags <script>like this<\script>. The same would be done with the CSS file but with style tags.

Problem

NodeJS doesnt have document so I cant just require the html file do ele.appendChild. The only other option that comes to my mind would be using REGEX but I would rather not use that.

TLDR

I need something that will let me do things like document.head.appendChild to an HTML file in nodejs.

1 Answers

I ended up using the JSDOM package. I am now aware of the advantages that sending multiple files can have, like browser caching. However this is a trade off that I need to make due to having amazing response times to begin with and very limited requests.

Related