Can I use jQuery with Node.js?

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

    in 2016 things are way easier. install jquery to node.js with your console:

    npm install jquery
    

    bind it to the variable $ (for example - i am used to it) in your node.js code:

    var $ = require("jquery");
    

    do stuff:

    $.ajax({
        url: 'gimme_json.php',
        dataType: 'json',
        method: 'GET',
        data: { "now" : true }
    });
    

    also works for gulp as it is based on node.js.

提交回复
热议问题