> For the complete documentation index, see [llms.txt](https://docs.nosto.com/techdocs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nosto.com/techdocs/apis/frontend/oss/nosto-js.md).

# Nosto JS

[Nosto JS](https://github.com/Nosto/nosto-js) is a wrapper for the client script, providing an easy way to interact with the Nosto service from your JavaScript or TypeScript applications.

For more information about JS API, see [Our documentation](https://docs.nosto.com/techdocs/apis/frontend/js-apis).

## Nosto stub

When using this library, it is not necessary to create the Nosto stub. It will be created automatically as soon as the library is imported for the first time.

## Initialization

The `init` function will load the latest version of the client script and add it to your page on runtime.

```js
import { init } from "@nosto/nosto-js"

await init({
  merchantId: "shopify-12345"
})
```

It returns a promise that resolves when the client script is fully loaded and initialized. However, awaiting it is optional.

## API access

Use the `nostojs` function exported from the library in the same way you would use `window.nostojs`. In fact, this is a typed wrapper over the window function.

```js
import { nostojs } from "@nosto/nosto-js"

await nostojs(async api => {
  const recommendations = await api.loadRecommendations()
  console.info(recommendations)
})
```

You may safely use this even before the `init` function has been called. Any early calls will be queued and processed later, when the client script is initialized.

## Mocking

Use the `mockNostojs` function to mock the Nosto API in unit tests. The function accepts partial API mocks and merges them with default mock API behavior:

```js
import { mockNostojs } from "@nosto/nosto-js/testing"
import dummyTagging from "./dummyTagging"
describe("Nosto integration", () => {

  beforeAll(() => {
    mockNostojs({
      pageTagging: () => dummyTaggging
    })
  })

})
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.nosto.com/techdocs/apis/frontend/oss/nosto-js.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
