sp-jsom-node

🚴 SharePoint JavaScript Object Model for Node.js

NPM

npm versionarrow-up-right Downloadsarrow-up-right Build Statusarrow-up-right Gitter chatarrow-up-right

sp-jsom-node provides a feasibility of using JSOM (CSOM, SharePoint Client Object Model) in Node.js.

sp-jsom-node patches global variables and request client which let's JSOM used to behave as if it were in it's usual environment - a browser's SharePoint page.

Supported SharePoint versions

  • SharePoint Online, Project Online

  • SharePoint 2019, 2016, Project Server

  • SharePoint 2013

  • SharePoint 2010 [not officially supported]

APIs list

Supported authentication scenarios

  • SharePoint On-Premise (2019, 2016, 2013):

    • User credentials (NTLM)

    • Form-based authentication (FBA)

    • Add-In Only permissions

    • ADFS user credentials

  • SharePoint Online:

    • User credentials (SAML)

    • Add-In Only permissions

    • ADFS user credentials

Installation

Usage examples

JsomNode Demo

Minimal setup (TypeScript)

First wizard run propmts for SharePoint site url and credentials strategy parameters.

Minimal setup (JavaScript)

Initiation with parameters

Async/Await usage

Client context runtime is extended with executeQueryPromise - promisified version of executeQueryAsync. Which allows coding with async/await in a "synchronous" handy style, having elegant and easily maintainable code.

Modules

By default, only core modules are loaded. Additional CSOM features can be requested in modules setting.

Modules listarrow-up-right.

Project server (PM.js)

JSOM Node Settings options

  • modules?: JsomModules[]; // On demand modules load | Default is ['core']

  • envCode?: 'spo' | '16' | '15'; // Loads different version of JSOM javascripts | Default is 'spo'

Synchronous initiation .init(context: IJsomNodeContext)

Async/wizard initiation .wizard(config?: IConfigSettings)

node-sp-auth-config optionsarrow-up-right

  • configPath?: string; // Path to auth config .json | Default is './config/private.json'

  • encryptPassword?: boolean; // Encrypts password to a machine-bind hash | Default is 'true'

  • saveConfigOnDisk?: boolean; // Saves config .json to disk | Default is 'true'

Settings can be left blank. Auth options in such a case will be asked by node-sp-auth-config optionsarrow-up-right in a wizard like approach.

Settings scenarios

  • No initial settings (defaults): wizard approach, covers console applications cases with user interaction

  • With explicitly defined authOptions:

    • external tools is in charge for preparing auth credentials in node-sp-auth format

    • credentials should not be dumped on disc

  • Config file with prepopulated credentials: schedule, job automation, continues integration

Integration tests

Integration tests

Bundling scripts

When creating automation scripts for production environment, e.g. Azure Job or Function or embedded application like Electron, it can be important to bundle and minify sources with positive performant effect as a result. Check examplearrow-up-right with bundling.

Inspiration and references

This project was mostly inspired by Vadim Gremyachevarrow-up-right's project - CSOMNodearrow-up-right, but implements JSOM in node in a bit different way, in TypeScript and supports different auth scenarious implemented in node-sp-autharrow-up-right by Sergei Sergeevarrow-up-right.

Last updated

Was this helpful?