# ngo

> Run Go commands from Node or CLI, Go env not required

Latest version **2.7.0** (published 2021-06-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install ngo
pnpm add ngo
yarn add ngo
bun add ngo
```

Provides the commands `ngo`, `ngo-binary`, `ngo-update`, `ngo-version`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.7.0 |
| Published | 2021-06-21 |
| First published | 2016-11-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 4 |
| Unpacked size | 15.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Andrew Carpenter |
| Maintainers | doesdev |
| Keywords | go, golang, environment, env, cli, interop, run, command |

## Links

- npm: https://www.npmjs.com/package/ngo
- Repository: https://github.com/doesdev/ngo
- Homepage: http://github.com/doesdev/ngo#readme
- Issues: https://github.com/doesdev/ngo/issues
- npm.io page: https://npm.io/package/ngo

## Dependencies (4)

- [execa](https://npm.io/package/execa.md) ^5.1.1
- [go-bin](https://npm.io/package/go-bin.md) ^1.4.0
- [semver](https://npm.io/package/semver.md) ^7.3.5
- [go-versions](https://npm.io/package/go-versions.md) ^1.3.2

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 2.7.0 (latest) — 2021-06-21
- 2.6.2 — 2020-04-15
- 2.6.1 — 2019-07-15
- 2.6.0 — 2019-06-08
- 2.5.2 — 2018-10-09
- 2.5.1 — 2018-10-09
- 2.5.0 — 2018-08-10
- 2.4.9 — 2018-04-15
- 2.4.8 — 2018-04-15
- 2.4.7 — 2018-04-15
- 2.4.6 — 2018-04-14
- 2.4.5 — 2018-03-21
- 2.4.4 — 2018-03-18
- 2.4.3 — 2018-03-18
- 2.4.2 — 2018-03-18
- … 13 more at https://npm.io/package/ngo/versions

## README

# ngo [![NPM version](https://badge.fury.io/js/ngo.svg)](https://npmjs.org/package/ngo)   [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)   [![Dependency Status](https://dependencyci.com/github/doesdev/ngo/badge)](https://dependencyci.com/github/doesdev/ngo)   [![Build status](https://ci.appveyor.com/api/projects/status/0wutjytsl4hmha1j?svg=true)](https://ci.appveyor.com/project/doesdev/ngo)   [![Build Status](https://travis-ci.org/doesdev/ngo.svg)](https://travis-ci.org/doesdev/ngo)   

> Run Go commands from Node or CLI, Go env not required

Will download latest binaries locally if Go isn't already in PATH

### BONUS

If you run a command and it fails with "cannot find package..." we'll try to install
said package(s). YAYS. :relieved:

## local install

```sh
$ npm install --save ngo
```

## cli install

```sh
$ npm install --global ngo
```

## usage

#### cli usage
```sh
$ ngo version
# go version go1.8.3 windows/amd64

# to update the `ngo` install of Go (won't update system version)
$ ngo-update
# go version go1.9.4 windows/amd64

# to set the `ngo` install of Go to a specific version (won't update system version)
$ ngo-version 1.12.0
# go version go1.12.0 windows/amd64

# to run a `go get` installed binary use this bs
$ ngo-binary golint test/fixtures/errors.go
# test\fixtures\errors.go:13:5: error var unexp should have name of the form errFoo
```

#### programmatic usage
returns promise that resolves to `execa` style object without the `child_process` goodies

```js
const goOpts = {}
const ngo = require('ngo')(goOpts)
const golint = ngo.bin('golint')

ngo('version').then(console.log).catch(console.error)
/* {
 stdout: 'go version go1.8.3 windows/amd64',
 stderr: '',
 code: 0,
 failed: false,
 killed: false,
 signal: null,
 cmd: 'C:\\Go\\bin\\go version'
} */

golint('main.go').then(console.log).catch(console.error)
```

## api

### const ngo = require('ngo')(`options`)
- **Purpose:** initialize `ngo`
- **Arguments:**
  - **options** *[`Object` - optional]*
    - **useLocal** *[`Boolean` `false`] - use locally downloaded Go binaries)*
    - **update** *[`Boolean` `false`] - update local install to latest*
    - **installDeps** *[`Boolean` `true`] - attempt to install missing packages*
    - **env** *[`Object`] - environment vars to set for the Go command*
    - **goRoot** *[`String`] - Go root path (ex. `/usr/local/go`)*
    - **goPath** *[`String`] - Go workspace path (ex. `~/work`)*
- **Returns:** `Function` (`ngo`) which executes Go commands

### ngo(`commandArgs`, `options`)
- **Purpose:** - execute `go` commands
- **Arguments:**
  - **commandArgs** *[`Array` | `String` - required] - argument(s) to call with `go` command*
  - **options** *[`Object` - optional]*
   - same options as [`child_process.spawn`](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options)
   - additonal options available same as [`execa`](https://github.com/sindresorhus/execa#options)
- **Returns:** `Promise` which resolves to [`execa`](https://github.com/sindresorhus/execa) styled object

### ngo.bin(`binary`)
- **Purpose:** - execute commands on binaries in the `GOBIN` directory
- **Arguments:**
  - **binary** [`String`] - name of binary file to be executed in returned function
- **Returns:** `Function` (identical to `ngo`, but runs specified binary instead of `go`)

### ngo.env
this is a copy of ngo's `process.env` with the Go environment variables added to it

## License

MIT © [Andrew Carpenter](https://github.com/doesdev)

---
_Source: https://npm.io/package/ngo · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
