Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report

jsdom 24.0.0

A JavaScript implementation of many web standards
Package summary
Share
0
issues
0
licenses
Package created
21 Nov 2011
Version published
21 Jan 2024
Maintainers
6
Total deps
0
Direct deps
0
License
MIT
Generating a report...
Hold on while we generate a fresh audit report for this package.

Frequently Asked Questions

What does jsdom do?

jsdom is a JavaScript implementation of various web standards, particularly the WHATWG DOM (Document Object Model) and HTML standards. It's designed to be utilized with Node.js and aims to mirror a subset of a web browser to allow for testing and scraping of real-world web applications. jsdom emulates a browser environment, such as JavaScript in an HTML page, running directly in Node.js. It does this by giving JavaScript a sandbox to interact with the DOM, as a web browser would do.

How do you use jsdom?

To use jsdom in your application, you first need to install it via npm by running npm install jsdom. Once it is installed, you can bring it into your JavaScript file and use it as follows:

const jsdom = require("jsdom");
const { JSDOM } = jsdom;

const dom = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`);
console.log(dom.window.document.querySelector("p").textContent); // Logs "Hello world"

In this code, a new instance of JSDOM is created, with the HTML string <!DOCTYPE html><p>Hello world</p> passed into the constructor. The dom object has a window property, which gives access to the entire emulated browser environment. From there, you can use familiar DOM APIs such as document.querySelector.

This is a simple usage example, but jsdom is highly adaptable with numerous options for simulating different scenarios.

Where are the jsdom docs?

The official documentation for jsdom, including a comprehensive API reference and usage examples, is available in the "README" file of the jsdom GitHub repository. The documentation covers everything from basic usage to advanced features and options for customizing the behavior of a jsdom instance.