# gatsby-core-utils

> A collection of gatsby utils used in different gatsby packages

Latest version **4.16.0** (published 2026-01-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install gatsby-core-utils
pnpm add gatsby-core-utils
yarn add gatsby-core-utils
bun add gatsby-core-utils
```

## Health

**Score 70/100 (B)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high maintenance score; popular repo; extremely popular.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.16.0 |
| Published | 2026-01-26 |
| First published | 2019-07-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.0.0 <26 |
| Dependencies | 16 |
| Unpacked size | 171.3 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 55939 |
| Author | Ward Peeters |
| Maintainers | pieh, kathmbeck, serhalp-netlify, mlgualtieri-gatsby, wardpeet |
| Keywords | gatsby, gatsby-core-utils |

## Links

- npm: https://www.npmjs.com/package/gatsby-core-utils
- Repository: https://github.com/gatsbyjs/gatsby
- Homepage: https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-core-utils#readme
- Issues: https://github.com/gatsbyjs/gatsby/issues
- npm.io page: https://npm.io/package/gatsby-core-utils

## Dependencies (16)

- [got](https://npm.io/package/got.md) ^11.8.6
- [tmp](https://npm.io/package/tmp.md) ^0.2.1
- [lmdb](https://npm.io/package/lmdb.md) 2.5.3
- [lock](https://npm.io/package/lock.md) ^1.1.0
- [fastq](https://npm.io/package/fastq.md) ^1.15.0
- [ci-info](https://npm.io/package/ci-info.md) 2.0.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^11.2.0
- [file-type](https://npm.io/package/file-type.md) ^16.5.4
- [hash-wasm](https://npm.io/package/hash-wasm.md) ^4.11.0
- [configstore](https://npm.io/package/configstore.md) ^5.0.1
- [import-from](https://npm.io/package/import-from.md) ^4.0.0
- [xdg-basedir](https://npm.io/package/xdg-basedir.md) ^4.0.0
- [resolve-from](https://npm.io/package/resolve-from.md) ^5.0.0
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.20.13
- [proper-lockfile](https://npm.io/package/proper-lockfile.md) ^4.1.2
- [node-object-hash](https://npm.io/package/node-object-hash.md) ^2.3.10

## Recent versions

- 4.16.0 (latest) — 2026-01-26
- 4.17.0-next.0 (next) — 2025-11-27
- 2.15.0 (latest-v3) — 2022-12-07
- 3.25.0 (latest-v4) — 2022-12-07
- 4.0.0-alpha-drupal-proxyurl.14 (drupal-proxyurl) — 2022-11-22
- 3.14.0-alpha-transformer-json.26 (alpha-transformer-json) — 2022-10-12
- 4.0.0-alpha-v5.d20221012t101120.57 (alpha-v5) — 2022-10-12
- 3.23.0-alpha-preview-gh-api.26 (preview-gh-api) — 2022-09-08
- 3.23.0-alpha-9689ff.25 (alpha-9689ff) — 2022-08-31
- 3.20.0-mdxv4-rc.124 (mdxv4-rc) — 2022-07-27
- 3.18.0-alpha-drupal-self-reference.18 (drupal-self-reference) — 2022-07-19
- 3.18.0-alpha-mdx-v2.68 (alpha-mdx-v2) — 2022-06-30
- 3.15.0-alpha-wp-image-cdn-auth.45 (wp-image-cdn-auth) — 2022-05-20
- 3.9.0-alpha-image-service2.14 (image-cdn) — 2022-02-21
- 3.8.0-alpha-image-service.35 (image-service) — 2022-02-13
- … 354 more at https://npm.io/package/gatsby-core-utils/versions

## README

# `gatsby-core-utils`

Utilities used in multiple Gatsby packages.

## Usage

```shell
npm install gatsby-core-utils
```

### createContentDigest

Encrypts an input using md5 hash of hexadecimal digest.

```js
const { createContentDigest } = require("gatsby-core-utils")

const options = {
  key: "value",
  foo: "bar",
}

const digest = createContentDigest(options)
// ...
```

### cpuCoreCount

Calculate the number of CPU cores on the current machine

This function can be controlled by an env variable `GATSBY_CPU_COUNT` setting the first argument to true.

| value           | description                                            |
| --------------- | ------------------------------------------------------ |
|                 | Counts amount of real cores by running a shell command |
| `logical_cores` | `require("os").cpus()` to count all virtual cores      |
| any number      | Sets cpu count to that specific number                 |

```js
const { cpuCoreCount } = require("gatsby-core-utils")

const coreCount = cpuCoreCount(false)
// ...
```

```js
const { cpuCoreCount } = require("gatsby-core-utils")
process.env.GATSBY_CPU_COUNT = "logical_cores"

const coreCount = cpuCoreCount()
// ...
```

### joinPath

A utility that joins paths with a `/` on windows and unix-type platforms. This can also be used for URL concatenation.

```js
const { joinPath } = require("gatsby-core-utils")

const BASEPATH = "/mybase/"
const pathname = "./gatsby/is/awesome"
const url = joinPath(BASEPATH, pathname)
// ...
```

### isCI

A utility that enhances `isCI` from 'ci-info` with support for Vercel and Heroku detection

```js
const { isCI } = require("gatsby-core-utils")

if (isCI()) {
  // execute CI-specific code
}
// ...
```

### getCIName

A utility that returns the name of the current CI environment if available, `null` otherwise

```js
const { getCIName } = require("gatsby-core-utils")

const CI_NAME = getCIName()
console.log({ CI_NAME })
// {CI_NAME: null}, or
// {CI_NAME: "Vercel"}
// ...
```

### createRequireFromPath

A cross-version polyfill for Node's [`Module.createRequire`](https://nodejs.org/api/modules.html#modules_module_createrequire_filename).

```js
const { createRequireFromPath } = require("gatsby-core-utils")

const requireUtil = createRequireFromPath("../src/utils/")

// Require `../src/utils/some-tool`
requireUtil("./some-tool")
// ...
```

### Mutex

When working inside workers or async operations you want some kind of concurrency control that a specific work load can only concurrent one at a time. This is what a [Mutex](https://en.wikipedia.org/wiki/Mutual_exclusion) does.

By implementing the following code, the code is only executed one at a time and the other threads/async workloads are awaited until the current one is done. This is handy when writing to the same file to disk.

```js
const { createMutex } = require("gatsby-core-utils/mutex")

const mutex = createMutex("my-custom-mutex-key")
await mutex.acquire()

await fs.writeFile("pathToFile", "my custom content")

await mutex.release()
```

### Hashing

Parts of [`hash-wasm`](https://github.com/Daninet/hash-wasm) are re-exported from `gatsby-core-utils` or used in custom functions. When working on hashing where you'd normally use `crypto` from Node.js, you can use these functions instead. They especially show their advantage on large inputs so don't feel obliged to _always_ use them. Refer to `hash-wasm`'s documentation for more details on usage for the re-exported functions.

```js
const { md5File, md5, createMD5, sha256, sha1 } = require("gatsby-core-utils")

// For md5, createMD5, sha256, sha1 refer to hash-wasm
await md5(`some-string`)

// md5File gives you the MD5 hex hash for a given filepath
await md5File(`package.json`)
```

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