You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
9 years ago | |
---|---|---|
src | 9 years ago | |
test | 9 years ago | |
.gitignore | 9 years ago | |
.npmignore | 9 years ago | |
.travis.yml | 9 years ago | |
README.md | 9 years ago | |
package.json | 9 years ago |
README.md
node-browser-environment

Simulates a global browser environment using jsdom
.
This allows you to run browser modules in node with minimal or no effort. Can also be used to test browser modules with any node test framework. Please note, only the DOM is simulated, if you want to run a module that requires more advanced browser features (like localStorage
), you'll need to polyfill that seperately.
❗️Warning
This module adds a lot of stuff to the global namespace, use with care.
Install
npm install --save node-browser-environment
Usage
// Init
require('node-browser-environment')();
// Now you have access to a browser like environment in node:
typeof window;
// 'object'
typeof document;
// 'object'
var div = document.createElement('div');
// HTMLDivElement
div instanceof HTMLElement
// true
By default everything in the jsdom
window namespace is tacked on to the node global namespace. If you want to trim this down you can pass an array of required properties:
// Init
require('node-browser-environment')(['window']);
typeof window;
// 'object'
typeof document;
// 'undefined'
You can of course also assign to a function:
var browserEnv = require('node-browser-environment');
browserEnv();
// or
import browserEnv from 'node-browser-environment';
browserEnv();
License
MIT © Luke Childs