npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-pnp-js

v0.1.3

Published

PnP-JS-Core (sp-pnp-js) with Node.js made easy

Downloads

48

Readme

PnP-JS-Core (sp-pnp-js) with Node.js made easy

NPM

npm version

Need help on SharePoint with Node.JS? Join our gitter chat and ask question! Gitter chat

node-pnp-js allows you to use pnp-js-core from Node.js environment.
node-pnp-js implements it's own version of NodeFetchClient (shipped with sp-pnp-js) which supports authentication with help of node-sp-auth module.


How to use

Install

npm install node-pnp-js --save

Import fetch client and configure pnp

import * as pnp from 'sp-pnp-js';
import NodeFetchClient from 'node-pnp-js';

pnp.setup({
    sp: {
        fetchClientFactory: () => {
            return new NodeFetchClient(credentials);
        }
    }
});

credentials - the same object (credentialOptions) provided for node-sp-auth module. That means you can use any authentication option from node-sp-auth you want.

Use PnP-JS-Core library in code:

new pnp.Web(siteUrl).get()
    .then(data => {
        console.log(`Your web title: ${data.Title}`);
    })

There are three different approaches you can use in order to provide your SharePoint site url.

1. Use Web or Site constructor (like in a sample above) with siteUrl constructor param:

pnp.setup({
    sp: {
        fetchClientFactory: () => new NodeFetchClient(test.creds)
    }
});

new pnp.Web(siteUrl).get()
    .then(data => {
        console.log(`Your web title: ${data.Title}`);
    })

2. Use baseUrl configuration parameter (coming from sp-pnp-js):

pnp.setup({
    sp: {
        fetchClientFactory: () => new NodeFetchClient(test.creds),
        baseUrl: siteUrl
    }
});

// now you can access your web using chaining syntax 
// (pnp.sp.web will reference the web with url you provided as baseUrl):
pnp.sp.web.get()
    .then(data => {
        console.log(`Your web title: ${data.Title}`);
    })

3. Use siteUrl constructor param for NodeFetchClient:

pnp.setup({
    sp: {
        fetchClientFactory: () => new NodeFetchClient(test.creds)
    }
});

// now you can access your web using chaining syntax 
// (pnp.sp.web will reference the web with url you provided as siteUrl param):
pnp.sp.web.get()
    .then(data => {
        console.log(`Your web title: ${data.Title}`);
    })

Use cases:

  1. Any Node.js project with SharePoint. It can be remote jobs, azure functions, daemons, etc.
  2. Build pipeline extensibility. You can easily enhance your gulp pipeline with custom actions touching SharePoint.
  3. Anything else you can do with Node.js and SharePoint :)

Development:

I recommend using VS Code for development. Repository already contains some settings for VS Code editor.

  1. git clone https://github.com/s-KaiNet/node-pnp-js.git
  2. npm install
  3. npm run build - runs typescript compilation

Integration testing:

  1. Rename file /test/integration/private.config.sample.ts to private.config.ts.
  2. Update information in private.config.ts with appropriate values (urls, credentials).
  3. Run gulp test-int.