JQuery how to introduce the use of Node.js
First install jQuery dependent
npm install jquery
Then install jsdom
npm install jsdom
The introduction of jQuery
The new right-dependent manner
var jsdom = require('jsdom');
const {JSDOM} = jsdom;
const {document} = (new JSDOM('<!doctype html><html><body></body></html>')).window;
global.document = document;
global.window = document.defaultView;
global.jQuery = require('jquery')(window);
const $= require('jquery')(require("jsdom").jsdom().defaultView);
This is the old way, it will complain
var $= require('jquery')(require("jsdom").jsdom().defaultView);
Reference article: https://www.cnblogs.com/codermen/p/7943678.html