Can I use jQuery with Node.js?

前端 未结 20 2213
清歌不尽
清歌不尽 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:05

    You have to get the window using the new JSDOM API.

    const jsdom = require("jsdom");
    const { window } = new jsdom.JSDOM(`...`);
    var $ = require("jquery")(window);
    

提交回复
热议问题