Can I use jQuery with Node.js?

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

    npm install jquery --save #note ALL LOWERCASE

    npm install jsdom --save

    const jsdom = require("jsdom");
    const dom = new jsdom.JSDOM(``);
    var $ = require("jquery")(dom.window);
    
    
    $.getJSON('https://api.github.com/users/nhambayi',function(data) {
      console.log(data);
    });
    

提交回复
热议问题