sharepoint
Adventures in uploading/listing/downloading documents in Microsoft SharePoint Online... using Node.js add new function fileIsExist and downloadFile
Getting Started
npm i @zsj1029/sharepoint -D
const Sharepoint = require('@zsj1029/sharepoint')
const sp = new Sharepoint('URL HERE')
sp.authenticate()
sp.getWebEndpoint()
sp.getContents(path)
sp.createFolder(path)
sp.deleteFolder(path)
sp.createFile(options) // options = { path, fileName, data }
sp.deleteFile(options) // options = { path, fileName }
sp.createFileChunked(options) // options = { path, fileName, stream, fileSize, chunkSize }
sp.fileIsExist(path) // path like '/TechnicalCommunications/ArchitectGenesis/Guide.pdf' in SharePoint, return true or false
sp.downloadFile(path, savePath) // path like '/TechnicalCommunications/ArchitectGenesis/Guide.pdf' in SharePoint
// savePath like './download/', if not pass, will return file stream
Test
First, set these to match your SharePoint environment:
Env Variable | Value |
---|---|
SHAREPOINT_URL |
This is the site we're aiming for, so something like https://example.sharepoint.com/sites/YourSite/
|
SHAREPOINT_USERNAME |
The username you want to connect to SharePoint with. Note this is the full username with an @ , so something like some.username@example.com
|
SHAREPOINT_PASSWORD |
And yup, the password to accompany SHAREPOINT_USERNAME . |
SHAREPOINT_DIR_PATH |
Path to where the files are. e.g. /Shared Documents/General
|
- Alternatively, you can edit a
/.env
file if you prefer (as per dotenv)
Then, run:
npm run test