Get Current User Properties Using PNP Js

Vinodh
 
SharePoint MVP
August 29, 2019
 
Rate this article
 
Views
6578

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 !…

Category : Office 365, OnPremise, PNP

Author Info

Vinodh
 
SharePoint MVP
 
Rate this article
 
Vinodh is a Microsoft MVP for SharePoint (Office Apps and Services) having 5+ years of experience in Microsoft Technologies. His interest and expertise includes SharePoint Online Development, PowerApps Development, Flows ...read more
 

Leave a comment