🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@braincloud/client

Package Overview
Dependencies
Maintainers
7
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@braincloud/client

brainCloud client for NodeJS

latest
Source
npmnpm
Version
6.0.1
Version published
Weekly downloads
5
-28.57%
Maintainers
7
Weekly downloads
 
Created
Source

brainCloud NodeJS client

Package renamed. This package now ships as @braincloud/client (the @braincloud npm scope). The old unscoped braincloud package is deprecated — switch your dependency to @braincloud/client. The API is unchanged; only the package name moved.

Doing server-to-server (S2S) work? Use the companion package @braincloud/s2s (formerly brainclouds2s) instead of this client library.

Installation

yarn add @braincloud/client
# or
npm install @braincloud/client

NOTE: peer dependency of @react-native-community/async-storage is only needed when used within a React-Native application, see below.

Usage

var bc = require("@braincloud/client")

function authenticated(response) {
    console.log("Did get Authenticated to profileId:" + response.data.profileId);
    var shareable = true;
    var replaceIfExists = true;
    _bc.brainCloudClient.file.prepareUserUpload("tests","dummyFile",shareable,replaceIfExists,)
}
_bc = new bc.BrainCloudWrapper("_mainWrapper");

secret = "aaaaaaaa-bbbb-0000-cccc-111111111111";
appId = "00000";

console.log("Initializing brainCloud");
_bc.initialize(appId, secret, "1.0.0");

console.log("Authenticating anonymously to brainCloud");
_bc.authenticateAnonymous(authenticated);

React-Native Usage

import { BrainCloudWrapper } from '@braincloud/client';

_bc = new bc.BrainCloudWrapper("_myApp");

secret = "aaaaaaaa-bbbb-0000-cccc-111111111111";
appId = "00000";

console.log("Initializing brainCloud");
_bc.initialize(appId, secret, "1.0.0");

console.log("Authenticating anonymously to brainCloud");
 _bc.authenticateAnonymous(function (response) {
     if (response.status === 200) {
         console.log("Did get Authenticated to profileId:" + response.data.profileId);
     }
});

See https://github.com/react-native-community/react-native-async-storage for additional information on AsyncStorage.

Running in nodejs without web interface (nodejs server)

If you plan to run this server side in nodejs, it is possible. But it will fail to build at first because of missing web components. Simply put this into your main code file:

// Set up XMLHttpRequest.
XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
window = {
    XMLHttpRequest: XMLHttpRequest
};
XMLHttpRequest.UNSENT = 0;
XMLHttpRequest.OPENED = 1;
XMLHttpRequest.HEADERS_RECEIVED = 2;
XMLHttpRequest.LOADING = 3;
XMLHttpRequest.DONE = 4;
// Set up WebSocket.
WebSocket = require('ws');
// Set up LocalStorage.
LocalStorage = require('node-localstorage/LocalStorage').LocalStorage;
os = require('os');
var configDir = os.homedir() + "/.bciot";
localStorage = new LocalStorage(configDir);
const BC = require('@braincloud/client');

And make sure to have the following NPM dependencies installed:

  • @braincloud/client
  • node-localstorage
  • ws
  • xmlhttprequest

Implementation notes

File Upload

The file upload works slightly different in this implementation if not used in the web. Instead of using XMLHttpRequest you need to use XMLHttpRequest4Upload. Also the file object passed into uploadFile call needs to be a Read Stream from the nodes fs module.

var fs = require("fs")
... 
_bc.brainCloudClient.file.prepareUserUpload("test2", fileName, shareable, replaceIfExists, fileSize, function (result) {
    if (result.status == 200) {
        var uploadId = result.data.fileDetails.uploadId;
        var xhr = new XMLHttpRequest4Upload();
        file2 = fs.createReadStream("./someFile.ext");
        file2.size = fileSize;
            xhr.addEventListener("load", transferComplete);
        xhr.addEventListener("error", transferFailed);
        console.log("Uploading file with id:" + uploadId + " (size : " + fileSize + " )");
        _bc.brainCloudClient.file.uploadFile(xhr, file2, uploadId);
    } else {
        console.log("Error preparing for upload, " + result.reason_code );
    }
}
...

Only load and error listeners are triggered in this implementations.

File upload is not yet supported in React-Native.

Sessions

Sessions are not maintained across executions of scripts. i.e. Each script must initialy login.

Keywords

braincloud

FAQs

Package last updated on 07 Jul 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts