![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
node-pnp-js
Advanced tools
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.
npm install node-pnp-js --save
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.
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.
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}`);
})
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}`);
})
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}`);
})
I recommend using VS Code for development. Repository already contains some settings for VS Code editor.
git clone https://github.com/s-KaiNet/node-pnp-js.git
npm install
npm run build
- runs typescript compilation/test/integration/private.config.sample.ts
to private.config.ts
.private.config.ts
with appropriate values (urls, credentials).gulp test-int
.FAQs
PnP-JS-Core (sp-pnp-js) with Node.js made easy
We found that node-pnp-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.