Getting started with Node.js

This is the official Prepr SDK for Node.js. It provided a standardized way
for your team to communicate with the Prepr API.


Get started by installing the SDK in your application, simply open a terminal and enter

npm i @preprio/nodejs-sdk

Set up a client

We don't want to repeat our configuration for every API call, that's why we suggest you create a client from which you make requests. Let's make a client by creating services/prepr.js with the following code.

// services/prepr.js

const { createPreprClient } = require('@preprio/nodejs-sdk')

const prepr = createPreprClient({
  token: '<YourAccessToken>', // required
  timeout: 4000, // Optional, default value 4000
  baseUrl: '', // default value (GraphQL API), for REST API use
  userId: null, // Optional, used for AB testing implmentations

module.exports = { prepr }

Great, now we have the configuration in one place. Now, we can import our configured Prepr client to perform requests.

Query the API

To perform GraphQL requests you can make use of our fluent builder, this is how it looks like

    // We created this earlier
    const {prepr} = require('./services/prepr')
    const result = await prepr
    .graphqlQuery(`GraphQL Query`)
    .timeout(8000) // Override globally set timeout for request cancellation
    .userId('...') // Override globally set userId for ab testing
    .token('xx-xx') // Update the Token used by the SDK for example when previewing staged content   
    .fetch() // Fetch the collections

Let's request all Pages in our Prepr environment.

    // We created this earlier
    const {prepr} = require('./services/prepr')
    const result = await prepr
        Pages {
            items {

To help you querying our API we've added multiple examples in the GraphQL section.

Reach out to us

You have questions about how to use this library?
Contact our support team at or join us on Slack.

You found a bug or want to propose a feature?
File an issue here on GitHub. Don't share any authentication info in any code before sharing it.