简体   繁体   English

将JavaScript文件加载到另一个JS文件中

[英]Load JavaScript file inside another JS file

I'm using node.js and socket.io and doing a server/client thing. 我正在使用node.jssocket.io并进行服务器/客户端操作。 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. 在我的服务器上,因为它不在网页上,有没有办法加载最新文件(或最新jQuery?),以便可以在Server js文件中使用jQuery函数。

I tried doing npm install jquery then drag the jquery folder into my node_modules folder onto my website. 我尝试执行npm install jquery然后将jquery文件夹拖到我的node_modules文件夹中到我的网站上。 Then at he top of my file I put var $ = require('jQuery'); 然后在我文件的顶部放var $ = require('jQuery'); and then I run it and I get the error Cannot find module 'location' 然后运行它,出现错误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. 我创建了一个小型测试应用程序(带有express),重新安装了jquery,事情开始起作用。

Checking my initial project a couple of changes seemed significant 检查我的初始项目,进行了几处更改,这似乎很重要

  1. I did an npm unisntall for jquery and jsdom 我为jquery和jsdom做了一个npm unisntall
  2. I did an npm install jquery (note, lowercase) 我做了一个npm install jquery(注意,小写)
  3. I changed my require('jQuery') to be require('jquery') (again, lowercase) 我将我的require('jQuery')更改为require('jquery')(再次,小写)

I think the significant part was removing and reinstalling jsdom and jquery but the others then were required to get things working again. 我认为重要的部分是删除并重新安装了jsdom和jquery,但随后又需要其他才能使事情再次起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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