# node-pnp-js

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

Latest version **0.1.3** (published 2017-10-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-pnp-js
pnpm add node-pnp-js
yarn add node-pnp-js
bun add node-pnp-js
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2017-10-08 |
| First published | 2017-05-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Sergei Sergeev |
| Maintainers | s-kainet |
| Keywords | pnp, sharepoint, node, pnp-js-core |

## Links

- npm: https://www.npmjs.com/package/node-pnp-js
- Repository: https://github.com/s-KaiNet/node-pnp-js
- Issues: https://github.com/s-KaiNet/node-pnp-js/issues
- npm.io page: https://npm.io/package/node-pnp-js

## Dependencies (3)

- [sp-pnp-js](https://npm.io/package/sp-pnp-js.md) ^3.0.1
- [node-fetch](https://npm.io/package/node-fetch.md) ^1.7.0
- [node-sp-auth](https://npm.io/package/node-sp-auth.md) ^2.1.1

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 0.1.3 (latest) — 2017-10-08
- 0.1.2 (beta) — 2017-10-07
- 0.1.1 — 2017-10-06
- 0.1.0 — 2017-08-16
- 0.0.1 — 2017-05-23

## README

# PnP-JS-Core (sp-pnp-js) with Node.js made easy

[![NPM](https://nodei.co/npm/node-pnp-js.png?mini=true)](https://nodei.co/npm/node-pnp-js/)

[![npm version](https://badge.fury.io/js/node-pnp-js.svg)](https://badge.fury.io/js/node-pnp-js)

### Need help on SharePoint with Node.JS? Join our gitter chat and ask question! [![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/sharepoint-node/Lobby)

`node-pnp-js` allows you to use [`pnp-js-core`](https://github.com/SharePoint/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`](https://github.com/s-KaiNet/node-sp-auth) module.  

---
## How to use  
### Install

```bash
npm install node-pnp-js --save
```

### Import fetch client and configure pnp 

```javascript
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`](https://github.com/s-KaiNet/node-sp-auth#params)) provided for [`node-sp-auth`](https://github.com/s-KaiNet/node-sp-auth) module. That means you can use any authentication option from [`node-sp-auth`](https://github.com/s-KaiNet/node-sp-auth) you want. 

### Use PnP-JS-Core library in code:

```javascript
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: 
```javascript
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`):
```javascript
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`:
```javascript
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`
2. `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`.

---
_Source: https://npm.io/package/node-pnp-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
