Can I use jQuery with Node.js?

前端 未结 20 1993
清歌不尽
清歌不尽 2020-11-22 05:42

Is it possible to use jQuery selectors/DOM manipulation on the server-side using Node.js?

20条回答
  •  一生所求
    2020-11-22 06:20

    As of jsdom v10, .env() function is deprecated. I did it like below after trying a lot of things to require jquery:

    var jsdom = require('jsdom');
    const { JSDOM } = jsdom;
    const { window } = new JSDOM();
    const { document } = (new JSDOM('')).window;
    global.document = document;
    
    var $ = jQuery = require('jquery')(window);

    Hope this helps you or anyone who has been facing these types of issues.

提交回复
热议问题