How to create a NPM command which executes a Go program?

42
November 21, 2020, at 10:00 PM

I have an NPM project (a React App) and want to execute a local go program by defining a command in the NPM package.json.

Basically I want it to look like this:


{
   ...
   "scripts": {
      "go-main": "go run ./my-go-program/main.go"
   }
   ...
}

and run it with: $ npm run go-main

The idea is, to execute the go program without actually installing go globaly or being dependend on OS exclusive binaries.

I tried using the npm go package, which installs go into the node_modules/.bin Folder. However, if you try to use it as described above, it won't process anything and (somehow) get stuck.

If you run the example above, following output will be printed:

$ npm run go-main
> my-project go-main C:\[...]\my-project\
> go run ./my-go-program/main.go

And it won't do anything until I hit ctrl+c.

Does anybody know why it doesnt do anything or how to execute go scripts as described above?

For the Records:

  • If I execute ./node_modules/.bin/go run ./my-go-program/main.go everything just works fine.
  • Every go command has the same behavior: go, go version, go -h and so on.

Edit for some context:

  • The program will change over time and needs to be used in a pipeline, as well as in several different OS.

  • Multiple People will have to use it, which did not use go before. In my opinion it would be nice if those wouldn't have to install go locally just for some little tool to setup a project.

  • The program is actually used to process some files and then save them for a react project.

  • However, I COULD of course precompile multiple versions of the go program for different OS, but then I would have to compile like 3 versions every time I change something. Thats why I am trying this.

Furthermore: Its not a discussion wether I want to do it or not. I want to know a solution or why I can't run the go executable in the node module bin folder :)

READ ALSO
gulp.pipe() and src() not a function

gulp.pipe() and src() not a function

New to Gulp not sure what to do here I installed every dependency gulp, reactify and browserify

34
How to use promise.allSettled with typescript?

How to use promise.allSettled with typescript?

Typescript build is failing as it does not seem to like PromiseallSetttled even though I have set ts config comilerOptions with "lib": [ "ES2020

42
Is there any way to pass a React component to Push notification using service worker and node js?

Is there any way to pass a React component to Push notification using service worker and node js?

I am looking for a solution where I can pass a react component (let's take a modal component) to the push notification parameter using service worker and node jsMy service worker code for normal push notification code is-

42
In PDFMake I set the height and weight of table, but it isn't work

In PDFMake I set the height and weight of table, but it isn't work

I've created tables with pdfmakeThe pagesize and the columns size was fixed

30