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.
In this setup, I use Node.js v22.12.0.
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 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.Or simply right click ➡️ Open with Code.
It was Windows 11 context menu bug back then when this was published — hence the "Show more options". They've fixed it.
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:⬆️ But using dynamic
import()in CommonJS adds async overhead, requires.defaultaccess for CommonJS modules, and can't run at top-level without anasyncwrapper.After you paste the template code above, it will look like this in VSCode:
You may change the
portto be other than 4000.We will use
publicfolder for ourHTML,CSS, andJS.Side note for the
configvariable in the 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 may 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.
⬆️ That is akin to —
This is how we make a cup of tea.
Proceeded with —
[Blah-blah-blah.]
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.
Thank you for visiting. See you next time. 👋











Comments
Post a Comment