Greetings. ๐
Sometimes, all we need is an HTML, a little CSS, and some JS — no React circus, no Vite firehose. But we still want our page to reload when we tweak a pixel.
In here, we will use Browsersync ๐ Node.js package. And of course, you need to install Node.js first on your system.
For code editor, I use VSCode ๐.
Assuming Node.js is already installed.
To check installed Node.js version on your system, open your terminal (Command Prompt / PowerShell — Windows) then type:
We can employ nvm to make Node.js installation easier to manage. Available for Windows (nvm-windows) and Linux (default nvm project — for Debian, Arch, Fedora, Slackware, etc. — provided you've got bash, zsh, or any POSIX-compliant shell.)
For macOs, we can install default nvm project — use Homebrew, add env to profile.
Setup
Let's do this on Windows 11 operating system — with Node.js is already installed.
-
Open your file explorer, navigate to a folder where your new project folder will reside.
Create a new folder. For example, name it as EXAMPLE.
Let's say the path is
D:\PROJECTS\EXAMPLE.Navigate to
EXAMPLEfolder in your file explorer ➡️ right click ➡️ Show more options ๐คท ➡️ Open with Code.By using this method, we will directly use VSCode for
EXAMPLEfolder.Now in VSCode, open the bottom panel and go to TERMINAL menu.
We can use
CTRL+`(backtick) to open that bottom panel. -
The terminal path would look like this:
I use PowerShell for my terminal in above screenshot.
-
Initialise
package.json. Type: -
We want to scope the Browsersync package in this current folder only, not globally. Thus, we type:
In that EXAMPLE folder, there will be a new
node_modulesfolder and apackage-lock.jsonfile. -
Create a new, blank
JSfile in that folder. Name itbrowserSync.js.Use this initial setup (template) for that blank file:
Browsersync currently supports only
CommonJS—requiremethod. The library was not originally designed as anESmodule.ES= ECMAScript, not Espagnol, unfortunately.We may do dynamic import if we insist on using
import:Hm.
๐➡️ ChatGPT 4o barges in:
Mate, using dynamic
import()in CommonJS adds async overhead, requires.defaultaccess for CommonJS modules, and can't run at top-level without anasyncwrapper.๐ซ I respond:
Aye. Nifty information, that.
ChatGPT 4o barges out. Away, I must. Flee! HAHAHA. ๐➡️๐ช Trips over the bloody ethernet cable. A thud is heard. ๐ฅ
You sound, mate?, I say.
Footnote: No such thing as this plot. I flipped it. It's called bonkerity.Titled:
Async & Thud: A Node.js Slapstick.It looks like this in VSCode:
You may change the
portto be other than 4000.We will use
publicfolder for ourHTML,CSS, andJS.A tiddy bit about the
configvariable in that snippet:-
server➡️ Folder to serve as root directory. -
host➡️ Hostname to bind the server (usually "localhost" or "0.0.0.0"). -
port➡️ Port number to serve on. -
files➡️ Glob pattern of files to watch and reload when changed.A glob is just a fancy developer word for a file pattern — a way to match multiple files or folders using wildcards.
It's like
regex, but it's not. ๐๐คฆGlob = Glob...al pattern matching. Global pattern matching. So when we say "glob pattern", it means global pattern matching pattern.
-
-
Create
publicfolder in that project. The structure will go like this: -
We then modify our
package.json.From this initial setup:
To this:
-
The base setup is complete. ☑️
We can run it using:
-
We tweak a bit the
HTML,CSS,JS, and page icon (favicon).
HTML
This is a template for the
HTML(public/index.html), so it won't look blank:
CSS
A template for the
CSS(public/css/index.css):
JS
JS(public/js/index.js):
Favicon
You might want to use your own
.icofile for thepublic/favicon.ico.I use this desk lamp icon.
-
Done. ✅
Final look:
Now, you can tinker around with that template. ๐
Every time there's a change in HTML / CSS / JS / other file (anything within
publicfolder), it will automatically be synchronised — no need to hit refresh or F5.Hit
CTRL+Cto stop the "watching" process in the VSCode bottom panel TERMINAL. Or simply close VSCode.For the
JSgenerated text, the phrasing, it should be "Served at" rather than "Served on". But hey. ๐ We're on a street corner wearing a trench coat. All of us are jammed into one trench coat. On a street corner. What a sight.
Additional — Full Stack
We can create and run another development server for backend, connect it to a database instance or other endpoint(s) — surely with different port. I always use nodemon for Node.js development (backend application) — combined with node-livereload (for frontend — monolithic), loggers: morgan, winston, and chalk — chalk package is used to colourise the logs.
This is like, this is how we make a cup of tea. Proceeds with bla-bla-bla. And this is how I wash the dishes and measure the mailman's nasal-feature length. No explanation about those.
Folder Structure
The entire folder structure looks like this:
We can add more folders and files to public folder. ๐ป
Why This Matters
๐ค This opening:
Sometimes, all we need is an HTML, a little CSS, and some JS... But we still want our page to reload when we tweak a pixel.
To further elaborate, this technique is useful for:
- Quick prototyping.
- Presenting (teaching) clean file structure.
- Sharing and replicating since no need for complex build tools.
Nice of you to drop in — don't be a stranger now. Ta-ra, be lucky.












Comments
Post a Comment