Sharepoint - PnPJS with on-prem sharepoint?

It is indeed possible to use PnP JS with SP OnPremise.

It supports both 2013 and 2016 as well as the upcoming 2019 environment. Under the hood, it is just a wrapper over the existing REST API endpoints.

Reference - Getting started with PnP JS


UPDATE JUNE 2019: Some things were changed in regards to PnPjs library and nodejs integration.

Please read below updated guidance on how to use it with on-prem SharePoint and Nodejs:

  1. mkdir pnp_test
  2. cd pnp_test
  3. npm init -y
  4. npm install @pnp/logging @pnp/common @pnp/odata @pnp/sp @pnp/graph @pnp/nodejs --save
  5. In order to send requests to on-prem SharePoint, we need to authenticate our user somehow. For that purpose, we're going to use a helper module called pnp-auth. So let's install it: npm install pnp-auth --save
  6. We're going to store credentials for a user in a json file. There is another module, node-sp-auth-config, which helps to generate a file with credentials: npm install -g node-sp-auth-config
  7. Generate a new credentials file with sp-auth:
    npx sp-auth init -p creds_ntlm.json

? SharePoint URL http://sp2019/sites/dev
? Authentication strategy User credentials (NTLM)
? User name administrator
? Domain sp
? Password *********

File saved to .../creds_ntlm.json
8. Create a new file index.js and put below code inside (JavaScript):

let bootstrap = require('pnp-auth').bootstrap;
let AuthConfig = require('node-sp-auth-config').AuthConfig;
let pnp = require('@pnp/sp'); 

let authConfig = new AuthConfig({ configPath: "./creds_ntlm.json", encryptPassword: true, saveConfigOnDisk: true })
bootstrap(pnp.sp, authConfig, "http://sp2019/sites/dev" )
pnp.sp.web.get().then(res => console.log(res)).catch(err => console.error(err));

Or TypeScript:

import { bootstrap } from 'pnp-auth';
import { AuthConfig } from 'node-sp-auth-config';
import { sp } from '@pnp/sp'; 

let authConfig = new AuthConfig({ configPath: "./creds_ntlm.json", encryptPassword: true, saveConfigOnDisk: true })
bootstrap(sp, authConfig, "http://sp2019/sites/dev" )
sp.web.get().then(res => console.log(res)).catch(err => console.error(err));  
  1. For JavaScript in console run node index.js, for TypeScript install ts-node (npm install ts-node --save-dev) and run npx ts-node index.ts

Original answer:

You can easily use PnPjs from nodejs application. However, you need a library, which wraps authentication. Check out sp-pnp-node library, which adds authentication support for pnpjs via node-sp-auth. NTLM (both V2 and V1) is supported.

Tags:

Pnp