简体   繁体   English

如何从服务器下载 js 文件并运行它?

[英]how to download a js file from a server and run it?

Is it possible to run a js file locally that downloads a secondary file and then run the latter?是否可以在本地运行下载辅助文件然后运行后者的js文件?

I know the best thing would be to download the file from the server and save it locally, I would just like to understand if there is still the possibility to do the above.我知道最好的办法是从服务器下载文件并将其保存在本地,我想了解是否仍有可能执行上述操作。

Example:例子:

Open terminal打开终端

1- node index js 1-节点索引js

2 - download scripts js in the same directory as index.js 2 - 下载与 index.js 相同目录下的脚本 js

3 - download is complete, start script js automatically. 3 - 下载完成,自动启动脚本js。

Even if it is possible to solve it with Node.js workarounds (like requireing your puppeteer script from an url etc.) I strongly suggest to use Git with your team to share the latest version of your script.即使可以使用 Node.js 解决方法来解决它(例如从 url 等中要求您的 puppeteer 脚本),我强烈建议您使用Z0BCC70105AD279503E31FE7B3F47B6Z的最新版本与您的团队共享脚本。 Version control is a must in modern software development, especially if you are working in a team.在现代软件开发中,版本控制是必须的,尤其是在团队工作的情况下。 By learning the 6-7 most basic git commands you can solve almost everything you need for the current use case.通过学习 6-7 个最基本的 git 命令,您几乎可以解决当前用例所需的一切。

There are many good tutorials how to get started with git, I recommend GitHub's https://try.github.io . There are many good tutorials how to get started with git, I recommend GitHub's https://try.github.io .

Of course: you need to convince your team to embrace the change, or in better case they are already using it for version control, so it will be familiar to them.当然:您需要说服您的团队接受更改,或者在更好的情况下,他们已经将其用于版本控制,因此他们会很熟悉。

You will need to:您将需要:

  1. Install Git locally;本地安装Git
  2. Create a new repository on a server where you can store the latest stable versions of all your scripts (if it is not an open source project make sure it is private, GitLab; GitHub and Bitbucket provides/hosts free private repositories that will suit your needs);在服务器上创建一个新的存储库,您可以在其中存储所有脚本的最新稳定版本(如果它不是开源项目,请确保它是私有的,GitLab;GitHub 和 Bitbucket 将免费提供/托管适合您的需求的私有存储库);
  3. Share the HTTPS (or SSH) URL of the repository with your team (eg: https://github.com/.../puppeteer-scripts.git ) which they can clone; Share the HTTPS (or SSH) URL of the repository with your team (eg: https://github.com/.../puppeteer-scripts.git ) which they can clone;
  4. Make sure your changes are pushed to the remote git repository;确保将您的更改推送到远程 git 存储库;
  5. Your team can pull the latest changes to their local computer (it will be their responsiblity to check if there were changes in the scripts, but you can notify them as well - there are automatic notifications if one starts to "watch" a git repository);您的团队可以将最新更改拉到他们的本地计算机(他们有责任检查脚本中是否有更改,但您也可以通知他们 - 如果有人开始“观看”git 存储库,则会自动通知) ;

Lastly最后

Git can be frightening at first sight, but it can be learned in a few days and it makes code sharing smooth within your team. Git 乍一看可能很吓人,但几天内就可以学会,它使您的团队内部的代码共享变得顺畅。

One of Git's tagline describes very well why it will solve your problem: Git 的标语之一很好地描述了它为什么会解决您的问题:

--everything-is-local --一切都是本地的

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

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