node-canvas-api
node-canvas-api copied to clipboard
Access the Canvas API using Node.js. 54 functions (and counting)! Pull requests are welcome and appreciated.
Canvas LMS API for Node.js
Canvas API functions bundled as a NPM package for Node.js.
Getting Started
These instructions will get you a copy of the project up and running on your local machine for use with your own API tokens and Canvas domains.
Prerequisites
- Install Node 8.0.0 or greater.
Installation
To use with node:
$ npm install node-canvas-api
Then, in wherever you want to use this package:
const canvasAPI = require('node-canvas-api')
Rename the sample.env file to .env and add your institution's domain and API access token.
Attached to the canvasAPI are a bunch of functions.
Run the attached functions!
Example Usage
Get information about self:
const canvasAPI = require('node-canvas-api')
canvasAPI.getSelf()
.then(self => console.log(self))
Get students in a course:
const { getUsersInCourse, getOptions } = require('node-canvas-api')
getUsersInCourse(12345, getOptions.users.enrollmentType.student) // first argument is Canvas course ID
.then(students => console.log(students))
Contribute
Contributions are welcome and greatly appreciated!
How to contribute
- Create an issue describing what contribution you are planning to make.
- Fork the repo.
- Add your contributions to the
sourcedirectory (and not thesrcdirectory. This directory is generated by Rollup during the build phase, and is what gets published to npm.) - If you add a file to
source, please add the file to the existingindex.jsinsidesource, so that during the build your contribution will be included insrc. - Test your code by creating a file in the root of the project directory, importing your code addition from
src, and running it. - Once you're happy with your contribution, open an pull request and I'll take a look.
Hypothetical scenario for adding new feature
- Add new file to
sourcefolder (say that the new file you want to add isgetUsersWithGradeThreshold.js) - In the
sourcefolder, there’s anindex.jsfile that lists all of the files you want exported tosrc. There you will add:export { default as getUsersWithGradeThreshold } from './getUsersWithGradeThreshold' - Run
npm run build, which will build the project and output your new function intosrc. - In the
index.jsat the root of the project that you create (this is not theindex.jsthat’s in thesourcefolder), import your new file fromsrclike this:const getUsersWithGradeThreshold = require('.src/getUsersWithGradeThreshold')and test by running the code:node index.js. - Once you’re happy that it works, create a PR.
Usage
License
This project is licensed under the MIT License.