node -v
npm -v
npx -vIf node -v prints a version for example, v22.19.0, you are good.
- Go to the downloads page: https://nodejs.org/en/download
- Download the macOS installer
- Run the installer and follow the prompts
- Once downloaded, open the terminal
- Verify:
bash
node --version
npm --version
sudo apt update
sudo apt install nodejs npm
# Verify
node -v
npm -v- Go to the downloads page: https://nodejs.org/en/download
- Download the Windows installer (.msi)
- Run the installer and follow the prompts
- Keep default options
- When you see the option to Automatically install the necessary tools, check it if you plan to build native modules
- Once downloaded, open the Command Prompt
- Verify:
bash
node -v
npm -v
npx -v
Create a file like script.js Run it:
> node script.jsconst title = document.querySelector('#title');// text
title.textContent = 'Welcome to the DOM workshop';
// HTML (avoid with untrusted input)
desc.innerHTML = '<strong>Bold</strong>';
// input value
const name = nameInput.value.trim() || 'friend';// page colors
document.body.style.backgroundColor = '#1c1e1f';
document.body.style.color = '#e7e7e7';
// element styles
title.style.padding = '0.25rem 0.5rem';
title.style.borderRadius = '6px';// create
const li = document.createElement('li');
li.textContent = `Item ${list.children.length + 1}`;
// insert
list.append(li); // end
list.prepend(document.createElement('li')); // start
// insert relative to another element
title.before('Intro: '); // before <h1>
title.after(' End'); // after <h1>
// quick HTML snippet
list.insertAdjacentHTML('beforeend', '<li><b>HTML item</b></li>');li.remove();
// or
list.removeChild(list.lastElementChild);// click
changeTitleBtn.addEventListener('click', () => {
title.textContent = 'Title updated via DOM';
});
// add item
addItemBtn.addEventListener('click', () => {
const item = document.createElement('li');
item.textContent = `Item ${list.children.length + 1}`;
list.append(item);
});