sppurge

Delete files from SharePoint document libraries using Node.js without hassles

NPM

npm version Downloads Build Status Gitter chat

Node.js module for files deletion from SharePoint document libraries.

Supported SharePoint versions

  • SharePoint Online

  • SharePoint On-Prem (2019, 2016, 2013)

How to use

Install

npm install sppurge

Usage

const sppurge = require('sppurge').default;

const context = {/*...*/};
const options = {/*...*/};

sppurge(context, options)
  .then(successHandler)
  .catch(errorHandler);

Arguments

Context

  • siteUrl - SharePoint site (SPWeb) url [string, required]

  • creds

    • username - user name for SP authentication [string, optional in case of some auth methods]

    • password - password [string, optional in case of some auth methods]

Additional authentication options:

Since communication module (sp-request), which is used in sppurge, had received additional SharePoint authentication methods, they are also supported in sppurge.

For more information please check node-sp-auth credential options and wiki pages.

Options

  • folder - relative folder in SharePoint to concat with filePath [string, optional, default: `` (empty string)]

  • filePath - relative file path, with extention [string, required in general, optional if localFilePath and localBasePath are both provided]

  • localFilePath - local full path to file [string, optional]

  • localBasePath - relative folder base path within project directory [string, optional]

Result file path is formed based on the following rule:

  • siteUrl + folder + filePath

  • If filePath is empty, then:

    • filePath = path.resolve(localFilePath).replace(path.resolve(localBasePath), '')

successHandler

Callback gets called upon successful file deletion.

errorHandler

Callback gets executed in case of exception inside sppurge. Accepts error object as first argument for callback.

Basic usage example (delete a single file)

Basic usage example (delete a folder)

Within Gulp task

Create React App usage scenario

Delete JS's build folder then upload all files from/build folder

One of the architectural decision in CRA is using hashes as a part of assets filenames. This allows avoiding issues related to browser cache. However, it can be challenging in term of deployment to SharePoint assets folders, as all filenames are different on each build. The further sample shows a simple use case approach of deleting files based on folder and name pattern.

Passwords storage

To eliminate any local password storing if preferable to use any two-way hashing technique, like cpass.

Last updated

Was this helpful?