Equivalent for "npm run ..."?

Hello World. Javascript noob here, though I do have a little working python under my belt.

I’m following an example for using the X-ray library to scrape data from web pages. The way the author expects the script to be run is from the command line with npm run foobar. How would this be done on HyperDev?

Here’s my work so far: https://hyperdev.com/#!/join/db357eb9-55bc-4785-ac3b-f1de2df4ed00

Wild guess here, but could you put that inside your “start” property in the package.json ?

"scripts": {
  "start": "npm run foobar",

Hi maphew,

HyperDev hasn’t yet a very good workflow for on-demand scripts that you just run once: it expects you to build a web application that runs continuously.

The workaround I suggest is to create a simple web app, and add an endpoint to it that calls the command you want (in this case npm run foobar) using the child_process module included in Node, or any wrapper library you prefer from npm.

On other news: we are experimenting with read-write filesystem, so you don’t need to write to /tmp any more :slight_smile:

If you have further questions or need more assistance don’t hesitate to ask!

When using start like that when and how often would foobar be called? On every page load? (I don’t want to hammer the destination server.)

thanks for the suggestion!

I went a little ways down the child_process route but got stuck because apparently server side commands can’t be used from the browser side (e.g. a button click), or at least not with the example I started with (ref), because require is not defined.

I think I’m just diving in too deep for my novice level, and need to run from a local install, so I’m not translating examples-I-barely-make-sense-of into a system-of-which-I-know-nothing. :wink:

It’d get called every time the node server starts up, so it wouldn’t be on every page load, unless the server had been put to sleep since the last page load.

You don’t need to call the server-side child_process commands from the browser side. You could trigger the server-side code with a GET route that is hit whenever someone clicks a button, or whatever it is that you want to start it.