Is it possible to use https://github.com/pnp/pnpjs with on-premise SharePoint with an external NodeJS application? Installing web parts is not an option I must perform read-only access.
If so, what versions of SharePoint are supported?
Is it possible to use https://github.com/pnp/pnpjs with on-premise SharePoint with an external NodeJS application? Installing web parts is not an option I must perform read-only access.
If so, what versions of SharePoint are supported?
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
httpntlm
in the pnpjs packages.json
but i don't seem to see it used anywhere
Commented
Aug 1, 2018 at 3:05
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:
mkdir pnp_test
cd pnp_test
npm init -y
npm install @pnp/logging @pnp/common @pnp/odata @pnp/sp @pnp/graph @pnp/nodejs --save
pnp-auth
. So let's install it: npm install pnp-auth --save
node-sp-auth-config
, which helps to generate a file with credentials: npm install -g node-sp-auth-config
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));
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.
npm install @pnp/[email protected] @pnp/[email protected] @pnp/[email protected] @pnp/[email protected]
.
This is the repo you want:
https://github.com/koltyakov/sp-pnp-node
It allows you to pass in auth info to the clientFactory.