micromentor-node-client v1.0.1
MicroMentor's NodeJS Client
Introduction
micromentor-node-client is a NodeJS client for MicroMentor's API.
References
Dependencies
For now, we use node-fetch, but will switch
to the built-in fetch once it becomes available in Node. Because node-fetch ver. 3 only
supports ESM modules, we use ver. 2.
Getting Started
First make sure you're using the correct version of Node (>=17). If you use nvm, you can
run nvm use and it will set the version specified in .nvmrc.
Now install the package with:
yarn add micromentor-node-clientor:
npm install micromentor-node-clientThen install the dependencies:
yarn installUsage
First initialize the client like this:
import micromentorClient from 'micromentor-node-client
const config = {
apiRootUrl: 'https://micromentor.org/api/v1',
authToken: <your API auth token>,
}
micromentorClient.init(config)Alternatively to the parameter config, you can also specify the config values
as environment files:
apiRootUrl: MM_API_API_ROOT_URL
authToken: MM_API_AUTH_TOKENWith these environment variables present, initialize the client with:
micromentorClient.init()Now you can retrieve and change data, i.e. create a profile/user:
micromentorClient.upsertBaseProfile({
user: {
first_name: 'Anton',
last_name: 'Zuflipuff',
},
})
.then((baseProfile) => {
console.log('Created new profile:', baseProfile)
})
.catch(error) {
console.error(error)
}Tests
Configure the test suite using an .env file:
MM_API_API_ROOT_URL=<url>
MM_API_AUTH_TOKEN=<your auth token>Run the test suite with:
yarn testNote: This library loads the .env config file only when running tests. In production, you
have to use the config parameter for init(), or load the environment variables elsewhere.
By default, the tests do not alter data through the API, i.e. no profiles are created. You can force data updates in tests with the environment variable:
TESTS_CAN_UPDATE_DATA=trueThe tests need some object IDs to retrieve data. You can supply them as environment variables:
MENTOR_PROFILE_ID_0=<mentor id>