GithubHelp home page GithubHelp logo

node-pnp-js's Introduction

DEPRECATED

USE pnp-auth instead

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.

node-pnp-js's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.