0

I am making a script for my office to take screenshots of web pages. I wish I could update my script whenever I want without having to send a new version to everyone. Is it possible to run an external JS file locally with nodejs on a server?

I'm trying to launch a js file with this code inside my computer, but it doesn't work.

const puppeteer = require('http://www.servername.com/app-screesnhot.js');
carver14
  • 41
  • 9
  • sending js to be executed on your server via an unsecured connection smells hazardous. i guess you could download it to the local server and then execute it. see https://stackoverflow.com/questions/5235904/node-js-download-and-execute-external-script – JoSSte Jun 07 '20 at 21:10
  • Sounds like you want to auto-update the script (or maybe package)...maybe [this](https://stackoverflow.com/questions/14006439/how-to-create-a-self-updating-node-js-application) will give you some possible ideas/solutions? – David784 Jun 07 '20 at 21:12
  • 1
    Have you considered making an NPM package and including that as a dependency of other software? You could then publish new versions to NPM. – Chase Jun 07 '20 at 21:12
  • your advice seems good to me, at the moment I have created a folder locally with all the components I need to make my script work hooked via package.json – carver14 Jun 07 '20 at 21:18

1 Answers1

1

You can create a Github gist if this is just a small simple script, and load it via a get request and then evaluate it.

However this sounds like a security problem, using eval to execute arbitrary code is generally bad practice.

A better way would be to publish your script as a package, but you would beed to manually update the server to use the new version.

dendog
  • 2,976
  • 5
  • 26
  • 63