In this article. I have explained how to get current user properties of the SharePoint user using pnp js.
Introduction To PNP Js
PNP means Patterns and Practices is a JavaScript library to accomplish SharePoint operations in more productive way for both SharePoint online and on-premise versions
In previous REST API Calls we fetch the current user properties using the below endpoint through AJAX
Endpoint: http:///_api/web/currentuser
Method: GET
Now let see how to done the same using PNP JS in the simplest way.
Import the PNP library from node
import pnp from "@pnp/pnpjs";
pnp.sp.web.currentUser.get().then(f => {
console.log("user", f);
})
It will return the successful response like below in JSON format
you can also use same JavaScript library of PNP Js in your normal JavaScript projects like Content editor webparts like below snippet
$pnp.sp.web.currentUser.get().then(function(response){
console.log("user", response);
});
Download it form CDN.
In my upcoming blogs let discuss more operations using PNP JS
Happy SharePointing !…
Leave a comment