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
- map function for objects (instead of arrays)
- Cross-Origin Read Blocking (CORB)
- 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
- How to make history.back() without getting a warning on the browser to reload the page?
- convert Hsl to rgb and hex
- How to solve ‘Redirect has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header’?
- jQuery setTimeout() Function [duplicate]
- How can I refresh a page with jQuery?
- How can I refresh a page with jQuery?
- How to add jQuery code into HTML Page
- TypeError: Router.use() requires middleware function but got a Object
- What does jQuery.fn mean?
- how to render a react component using ReactDOM Render
- ‘react-scripts’ is not recognized as an internal or external command
- webpack: Module not found: Error: Can’t resolve (with relative path)
- Bootstrap Dropdown menu is not working
- ajax jquery simple get request
- What’s the source of Error: getaddrinfo EAI_AGAIN?
- jquery SlideToggle effect in upward direction?
- How can I determine if a variable is ‘undefined’ or ‘null’?
- Set timeout for ajax (jQuery)
- How can I upload files asynchronously with jQuery?
- How do I format date in jQuery datetimepicker?
- Express Render not working return error: No default engine was specified and no extension was provided
- Unable to preventDefault inside passive event listener
- SecurityError: Blocked a frame with origin from accessing a cross-origin frame
- What is causing the error `string.split is not a function`?
- Uncaught TypeError: data.push is not a function
- Expressjs / Node.js – res.redirect() not loading page
- Using async/await with a forEach loop
- What is causing the error `string.split is not a function`?
- Uncaught TypeError: Cannot read property ‘top’ of undefined
- Scroll Automatically to the Bottom of the Page
- npm WARN … requires a peer of … but none is installed. You must install peer dependencies yourself
- How do I check if string contains substring?
- Basic Ajax send/receive with node.js
- How to check a radio button with jQuery?
- Get current URL with jQuery?
- TypeError: $(…).modal is not a function with bootstrap Modal
- How to add a “readonly” attribute to an ?
- JQuery $(“#content”).append not working
- How to fix Cannot find module ‘typescript’ in Angular 4?
- using jQuery $(this).addClass not working, simple code not working
- HTML text input allow only numeric input
- How to use jQuery in chrome extension?
- How to change value of object which is inside an array using JavaScript or jQuery?
- How to detect pressing Enter on keyboard using jQuery?
- Chrome/jQuery Uncaught RangeError: Maximum call stack size exceeded
- how to use react require syntax?
- How to get height of div in px dimension
- jQuery: Uncaught Error: Syntax error, unrecognized expression
- SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
- How to use in jQuery :not and hasClass() to get a specific element without a class
- What is the best way to remove a table row with jQuery?
- Bootstrap popover is not working
- How to display raw JSON data on a HTML page
- How to get unique values in an array
- How to fix Error: listen EADDRINUSE while using NodeJS?
- Only on Firefox “Loading failed for the script with source”
- JQuery get the title of a button
- Trying to load jquery into tampermonkey script
- How to add a button dynamically using jquery
- How to format a UTC date as a `YYYY-MM-DD hh:mm:ss` string using NodeJS?
- jQuery if Element has an ID?
- Complex JSON nesting of objects and arrays
- Preloading images with jQuery
- jQuery – Increase the value of a counter when a button is clicked
- Get the size of the screen, current web page and browser window
- How to reload/refresh jQuery dataTable?
- Write / add data in JSON file using Node.js
- What does `node –harmony` do?
- Simulate a click on ‘a’ element using javascript/jquery
- How can I remove a style added with .css() function?
- How to use aria-expanded=”true” to change a css property
- Error: Couldn’t find preset “es2015” relative to directory “/Users/username”
- How can I get my Calculate Contact Form 7 field to update with jQuery? [closed]
- Contact Form 7 – Uncaught TypeError: wpcf7.initForm is not a function [closed]
- How to set javascript options for select2 in PHP array of plugin
- how to prevent added meta box from being injected with style=”position: fixed; top: 56px;” at scroll down
- How to run Javascript popup modal in a loop?
- Remove escape characters from JSON string pulled from a database
- Styling parent based on a child element of a child in a WordPress page