To use jquery in node, you need to have two separate node package installations.
- jquery
- jsdom to create a dummy window object which jquery can use.
Installation:
npm install jquery npm install jsdom
In code:
var jsdom = require("jsdom").jsdom; global.$ = require('jquery/dist/jquery')(jsdom().createWindow());
Or, with newer versions of jsdom:
require("jsdom").env("", function(err, window) { if (err) { console.error(err); return; } var $ = require("jquery")(window); });
Using global.$ will make the jquery object($) available globally in your project.
Related Posts:
- How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)
- NPM ELIFECYCLE error – using node server.js command
- Node.js – SyntaxError: Unexpected token import
- After $npm install, Getting Error: Cannot find module ‘../lib/utils/unsupported.js’
- Node.js – SyntaxError: Unexpected token import
- Node.js Port 3000 already in use but it actually isn’t?
- npm – EPERM: operation not permitted on Windows
- AJAX response error: net::ERR_EMPTY_RESPONSE
- Node update a specific package
- Cannot find module ‘internal/fs’ after upgrading to node 7
- npm WARN enoent ENOENT: no such file or directory, open ‘C:\Users\Nuwanst\package.json’
- Maximum call stack size exceeded on npm install
- NPM install fails with node-gyp
- events.js: 141 throw er; // Unhandled ‘error’ event
- How to make a discord bot create an invite for every server it joins?
- map function for objects (instead of arrays)
- How to change CSS using jQuery?
- How to properly use jsPDF library
- Start script missing error when running npm start
- How do I redirect to another webpage?
- How do I redirect to another webpage?
- Cross-Origin Read Blocking (CORB)
- How can a Discord bot create a hyperlink in a Discord message in an embed or in general? [closed]
- jQuery append() vs appendChild()
- How to you store data for each discord user in the discord server?
- How to replace innerHTML of a div using jQuery?
- Uncaught ReferenceError: $ is not defined?
- Uncaught ReferenceError: jQuery is not defined [duplicate]
- How do I check whether a checkbox is checked in jQuery?
- Babel 6 regeneratorRuntime is not defined
- syntax error: unexpected token <
- Error OPTIONS net::ERR_CONNECTION_REFUSED
- TypeError: Converting circular structure to JSON in nodejs
- ReferenceError: $ is not defined
- Uncaught ReferenceError: jQuery is not defined [duplicate]
- What does [object Object] mean?
- Remove class using jQuery
- How do I check whether a checkbox is checked in jQuery?
- Babel 7 – ReferenceError: regeneratorRuntime is not defined
- jQuery document.createElement equivalent?
- How to make history.back() without getting a warning on the browser to reload the page?
- Getting a UnhandledPromiseRejectionWarning when testing using mocha/chai
- JQuery – $ is not defined
- Cannot read property ‘push’ of undefined when combining arrays
- Difference between npx and npm?
- Toggle show/hide on click with jQuery
- convert Hsl to rgb and hex
- Client on Node.js: Uncaught ReferenceError: require is not defined
- Error: Can’t set headers after they are sent to the client
- How can a Discord bot create a hyperlink in a Discord message in an embed or in general?
- Pure JavaScript equivalent of jQuery’s $.ready() – how to call a function when the page/DOM is ready for it [duplicate]
- Getting a UnhandledPromiseRejectionWarning when testing using mocha/chai
- JQuery – $ is not defined
- Cannot read property ‘push’ of undefined when combining arrays
- require is not defined? Node.js
- Client on Node.js: Uncaught ReferenceError: require is not defined
- Error: Can’t set headers after they are sent to the client
- TypeError: Router.use() requires middleware function but got a Object
- jQuery .on(‘change’, function() {} not triggering for dynamically created inputs
- How to create a jQuery function (a new jQuery method or plugin)?
- jQuery: Wait/Delay 1 second without executing code
- Express error – TypeError: Router.use() requires middleware function but got a Object
- Failed to load resource: the server responded with a status of 500 (Internal Server Error) in Bind function
- Cannot GET / Nodejs Error
- Scroll to an element with jQuery
- What is NODE_ENV and how to use it in Express?
- Download File Using JavaScript/jQuery
- How to solve ‘Redirect has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header’?
- How to deal with net::ERR_SSL_PROTOCOL_ERROR?
- Node.js heap out of memory
- How can I scroll to an element using jQuery?
- Reactjs – Form input validation
- jQuery.click() vs onClick
- jQuery setTimeout() Function [duplicate]
- jQuery Get Selected Option From Dropdown
- Disabling and enabling a html input button
- await is only valid in async function
- Scroll to an element with jQuery
- How to set NODE_ENV to production/development in OS X
- Download File Using JavaScript/jQuery
- await is only valid in async function
- Check if checkbox is checked with jQuery
- How can I refresh a page with jQuery?
- How can I refresh a page with jQuery?
- Getting Error “Form submission canceled because the form is not connected”
- Heroku: “No default language could be detected for this app” error thrown for node app
- Heroku: “No default language could be detected for this app” error thrown for node app
- How to add jQuery code into HTML Page
- How can I get the data-id attribute?
- document.getElementById vs jQuery $()
- TypeError: Router.use() requires middleware function but got a Object
- Check if checkbox is checked with jQuery
- What does “res.render” do, and what does the html file look like?
- How to import jquery using ES6 syntax?
- How to filter an array/object by checking multiple values
- How to obtain username from Promise
? - What does jQuery.fn mean?
- Getting Error “Form submission canceled because the form is not connected”
- Is there a link to the “latest” jQuery library on Google APIs?
- how to render a react component using ReactDOM Render