Setting up Node.js
Published: | Author: Russ Weakley
What this tutorial is about
Running axe-core in the browser console only required Chrome. The next tutorials in this series run axe-core outside the browser, so you'll need a few tools installed first.
This tutorial walks you through the setup, step by step, on a Mac or on Windows. Where the instructions differ, you'll see a Mac version and a Windows version.
By the end, you'll have installed Node.js, created a project folder, installed the accessibility tools, and run your first check.
Before you start
You'll need:
- A Mac or Windows computer
- An internet connection
- Permission to install software on your computer. On some work computers, this needs approval from your IT team.
- About 20 to 30 minutes
What's in this tutorial
Check your computer
- Step 1. Open your command line app
- Step 2. Check if you have Node.js
- Step 3. Check if you have npm
- Step 4. Check if you have Google Chrome
- Step 5. Show file name extensions (Windows only)
Set up your project
- Step 6. Create a project folder
- Step 7. Turn the folder into a project
- Step 8. Install the accessibility tools
- Step 9. Download Playwright's browser
Connect to Chrome
- Step 10. Find your Chrome version
- Step 11. Install a matching ChromeDriver
- Step 12. Run your first check
Check your computer
Step 1. Open your command line app
You'll be typing commands into a command line app. It lets you control your computer by typing instead of clicking. It looks a bit plain, but you only need a handful of commands, and each one is explained as you go.
- Mac: the app is called Terminal. To open it, press Command + Space, type
Terminal, then press Return. - Windows: the app is called Command Prompt. To open it, press the Windows key, type
Command Prompt, then press Enter.
How to use the commands in this tutorial:
- Copy each command exactly as it's shown, paste it into your command line app, then press Return (Mac) or Enter (Windows). To paste, press Command + V on Mac. On Windows, press Ctrl + V or right-click inside the window.
- Run one command at a time, and wait for it to finish before entering the next one. You'll know it's finished when the command prompt appears again. On Windows, this looks something like
C:\Users\yourname>. - You may see warnings containing words like warn or deprecated. These don't necessarily mean something has gone wrong. Check whether the command completed successfully before moving on.
Watch out for:
- On Windows, use Command Prompt rather than PowerShell for this tutorial. PowerShell can sometimes block npm commands with an error saying "running scripts is disabled on this system". Using Command Prompt avoids this issue.
- To check you're in Command Prompt, look at the line where you type. If it starts with
PS, likePS C:\Users\yourname>, you're in PowerShell. Close it and open Command Prompt instead.
Step 2. Check if you have Node.js
Node.js is a program that lets your computer run JavaScript outside a web browser. The accessibility tools in this series are written in JavaScript, so they need Node.js to work.
Type:
node -v
(The -v is short for "version".)
You should see a version number that starts with the letter v, such as v24.13.0.
What the number means: Node.js versions have three numbers. For these tutorials, you'll need version 22.12 or later, but it's best to use a supported LTS version.
v22.12.0or later in the 22 series, or a supported version 24 or 26: you can continue.- Version 20 or earlier, or an unsupported version such as 23: follow the installation steps below.
If you see an error such as command not found on Mac or 'node' is not recognized as an internal or external command on Windows, Node.js may not be installed.
If Node.js is missing or needs updating:
- Go to nodejs.org.
- Download the version marked LTS, which stands for "Long Term Support". This is the recommended version for most people. On Windows, choose the Windows Installer (.msi).
- Open the downloaded file and follow the installation instructions.
- Mac: your Mac may ask for your password. That's normal.
- Windows: you can accept the default settings, with one exception. If you see an option called Tools for Native Modules, leave it unticked. You don't need these extra tools for this tutorial. Windows may also ask whether you want to allow the installer to make changes to your device. Click Yes if it's the installer you downloaded from the official Node.js website.
- Close your command line app completely, then open it again.
- Mac: press Command + Q to quit Terminal.
- Windows: click the X in the corner of Command Prompt, or type
exitand press Enter.
- Type
node -vagain to check that Node.js is installed and meets the version requirement.
Step 3. Check if you have npm
npm stands for "Node Package Manager". It downloads and installs extra software, called packages, that other people have written. You'll use it to install the accessibility tools.
npm normally comes with Node.js, so you should already have it installed.
Type:
npm -v
You should see a version number, such as 10.9.2. This means npm is installed and responding.
If you see an error saying "command not found" (Mac) or "'npm' is not recognized" (Windows), try installing Node.js again using the instructions in step 2.
Step 4. Check if you have Google Chrome
The accessibility tools in this tutorial use Google Chrome to check web pages, so you'll need Chrome installed.
- Mac: if you don't have Chrome, download it from google.com/chrome.
- Windows: if you don't have Chrome, download it from google.com/chrome.
Step 5. Show file name extensions (Windows only)
Mac: you can skip this step.
Windows: a file name extension is the part after the dot in a file name, such as .js in check.js. It tells your computer what kind of file it is.
Windows usually hides file extensions. This means a file named check.js.txt might appear as check.js, even though it's actually a text file. Showing file extensions helps you avoid this problem.
On Windows 11:
- Open File Explorer (press Windows key + E).
- Click View in the menu at the top.
- Point to Show, then click File name extensions so it has a tick next to it.
On Windows 10:
- Open File Explorer (press Windows key + E).
- Click the View tab at the top.
- Tick the File name extensions box.
Watch out for:
- A code editor, such as VS Code, is a good way to create and edit code files on Mac and Windows.
- On Mac, avoid TextEdit. It can save files as formatted text instead of plain text.
- On Windows, Notepad works for editing existing code files. However, when creating a new file, Save As may add
.txtto the name. To avoid this, choose All files under Save as type.
Set up your project
Step 6. Create a project folder
You'll keep everything for this series in one folder. Enter the following commands one at a time.
Mac:
cd ~/Documents
cd stands for "change directory". A directory is another word for a folder. This command moves you into your Documents folder.
Windows:
cd %USERPROFILE%
This moves you into your user folder, usually C:\Users\yourname. The %USERPROFILE% part is a shortcut for the location of that folder.
Then, on both Mac and Windows:
mkdir axe-learning
mkdir stands for "make directory". This creates a new folder called axe-learning.
cd axe-learning
This moves you into the new folder.
To check it worked:
- Mac: type
pwdand press Return. This stands for "print working directory", which means "show me which folder I'm in". You should see a location ending in/Documents/axe-learning. - Windows: type
cdand press Enter. This shows which folder you're in. You should see something likeC:\Users\yourname\axe-learning.
Important: You'll need to be inside your axe-learning folder for the remaining commands in this tutorial. If you close your command line app and return later, use one of these commands to get back:
- Mac:
cd ~/Documents/axe-learning - Windows:
cd %USERPROFILE%\axe-learning
Watch out for:
- On Windows, it's best to keep your project outside folders that sync with OneDrive. Some computers automatically sync the Documents folder, and the tools you're about to install can create thousands of small files. Keeping the project in your user folder usually avoids this problem.
Step 7. Turn the folder into a project
Type:
npm init -y
This sets up your folder as an npm project, so you can install tools into it. The -y stands for "yes" and accepts the default settings, so you won't be asked any questions.
You'll see some text appear on screen. This is npm showing you what it created: a file called package.json. Think of this as the project's notebook. It keeps information about your project, including the tools it uses.
To check it worked, list the files in your folder:
- Mac: type
lsand press Return.lsstands for "list". - Windows: type
dirand press Enter.diris short for "directory".
You should see package.json in the list.
Step 8. Install the accessibility tools
Type:
npm install @axe-core/cli playwright @axe-core/playwright
This installs three tools in one go. It may take a few minutes.
@axe-core/clichecks a web page for accessibility problems when you type one command. "CLI" stands for "command line interface", which means a tool you use by typing commands rather than clicking buttons.playwrightcontrols a web browser automatically. It can open pages, click buttons and fill in forms, just like a person would.@axe-core/playwrightlets you run accessibility checks in a browser controlled by Playwright. This is useful when you need to interact with a page before testing it.
You'll notice a new folder called node_modules appears in your project folder. That's where npm stores the tools it installed. You don't need to open or change anything in it for these tutorials.
To check it worked, type:
npm ls
You should see the three tools listed, each with a version number.
Step 9. Download Playwright's browser
Playwright uses its own version of Chromium, separate from the Google Chrome browser you normally use. Type:
npx playwright install chromium
Chromium is the free, open-source browser that Google Chrome is built on. This download may take a few minutes.
You'll see progress information while it downloads. It's finished when the command prompt appears again.
Connect to Chrome
Step 10. Find your Chrome version
The axe command line tool uses a helper program called ChromeDriver to control Chrome. ChromeDriver needs to be compatible with your version of Chrome, so let's find out which version you have.
- Open Google Chrome.
- Click in the address bar, type
chrome://version, then press Return (Mac) or Enter (Windows). - Look for the Chrome version number. It should look something like
155.0.8059.85.
The first number, in this case 155, is the main version. Make a note of it.
Step 11. Install a matching ChromeDriver
Type this, replacing 155 with your main Chrome version number:
npm install chromedriver@155
This installs a version of ChromeDriver that matches your main Chrome version and adds it to your project.
To check it worked, type:
npm ls
You should now see four tools listed, including chromedriver, with a version number starting with your Chrome version.
Step 12. Run your first check
Use the command for your computer:
Mac:
npx axe https://example.com --chromedriver-path "node_modules/chromedriver/lib/chromedriver/chromedriver"
Windows:
npx axe https://example.com --chromedriver-path "node_modules\chromedriver\lib\chromedriver\chromedriver.exe"
You're now running your first axe-core accessibility test! The command:
- Opens the page in Chrome, without displaying a browser window.
- Checks the page for common accessibility problems.
- Lists any problems it finds.
Here's what the different parts of the command mean:
npxcomes with npm. It runs a tool you've installed in your project.axeis the accessibility testing tool you're running.https://example.comis the demonstration website you're testing.--chromedriver-pathtells axe where to find the ChromeDriver you installed in step 11.
You'll need to include --chromedriver-path each time you run an axe check in this tutorial.
The test may take a few seconds to complete. When it's done, you'll see any accessibility issues axe-core found, along with the total number of violations.
To check a different page, replace https://example.com with that page's address.
Watch out for:
- An error mentioning "session not created" or "This version of ChromeDriver only supports Chrome version" usually means ChromeDriver and Chrome don't match. Check the version number you used in step 11. The error may also show your Chrome version, in a line like
Current browser version is 155.0.8059.85. - The error message may suggest a tool called
browser-driver-manager. You don't need to use it for this tutorial. You've already installed ChromeDriver with npm in step 11. - Chrome updates automatically. If you see a version mismatch error after an update, repeat steps 10 and 11 using your new Chrome version.
Related articles
This tutorial is part of a series on accessibility testing with axe-core and Playwright. The articles in this series are: