简体   繁体   中英

Load JavaScript file inside another JS file

I'm using node.js and socket.io and doing a server/client thing. On my Server, is since its' not on a webpage, is there a way I can load the latest file (or latest jQuery?) so I can use jQuery functions inside my Server js file.

I tried doing npm install jquery then drag the jquery folder into my node_modules folder onto my website. Then at he top of my file I put var $ = require('jQuery'); and then I run it and I get the error Cannot find module 'location'

Thanks

I was getting this same issue. I created a small test applications (with express), installed jquery afresh and things started working.

Checking my initial project a couple of changes seemed significant

  1. I did an npm unisntall for jquery and jsdom
  2. I did an npm install jquery (note, lowercase)
  3. I changed my require('jQuery') to be require('jquery') (again, lowercase)

I think the significant part was removing and reinstalling jsdom and jquery but the others then were required to get things working again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM