Everything you need to start building your app in Learnosity, with Node.js and the JavaScript programming language.
(Prefer another language? Click here)
An official Learnosity open-source project.
- Overview: what does it do?
- Requirements
- Installation
- Quick start guide
- Next steps: additional documentation
- Contributing to this project
- License
- Usage tracking
- Further reading
The Learnosity Node.js SDK makes it simple to interact with Learnosity APIs.
It provides a number of convenience features for developers, that make it simple to do the following essential tasks:
- Creating signed security requests for API initialization, and
- Interacting with the Data API.
For example, the SDK helps with creating a signed request for Learnosity:
Once the SDK has created the signed request for you, your app sends that on to an API in the Learnosity cloud, which then retrieves the assessment you are asking for, as seen in the diagram below:
This scenario is what you can see running in the Quick start guide example (see below).
There's more features, besides. See the detailed list of SDK features on the reference page.
-
Runtime libraries for Node.js installed. (instructions)
-
To follow the tutorial on this page, also install some other libraries:
- Express.js, a minimal web framework,
- The EJS templating language, and
- The UUID library. These are not actually a requirement of the SDK itself, so if your app doesn't use these libraries, no need to install them. They are only required for the tutorial on this page.
Not using Node.js? See the SDKs for other languages.
The Learnosity SDK - Node.js is verified against Active LTS and Maintenance LTS releases of Node.js.
Using NPM is the recommended way to install the Learnosity SDK for Node.js in production. The easiest way is to run this from your parent project folder:
npm install https://github.com/Learnosity/learnosity-sdk-nodejs
To follow the tutorial on this page, also install some other libraries:
- Express.js, a minimal web framework,
- The EJS templating language, and
- The UUID library. Install these by running the following commands from the root folder of the project.
npm install express
npm install ejs
npm install uuid
Note: these additional libraries are not required by the Learnosity SDK. They are only required for the tutorial on this page.
Download the latest version of the SDK as a self-contained ZIP file from the GitHub Releases page. The distribution ZIP file contains all the necessary dependencies.
One downloaded, run this command from the root folder to install dependencies:
npm install
To follow the tutorial on this page, also install some other libraries:
- Express.js, a minimal web framework,
- The EJS templating language, and
- The UUID library. Install these by running the following commands from the root folder of the project.
npm install express
npm install ejs
npm install uuid
Note: these additional libraries are not required by the Learnosity SDK. They are only required for the tutorial on this page.
To install from the terminal, run this command:
git clone [email protected]:Learnosity/learnosity-sdk-nodejs.git
To follow the tutorial on this page, also install some other libraries:
- Express.js, a minimal web framework,
- The EJS templating language, and
- The UUID library. Install these by running the following commands from the root folder of the project.
npm install express
npm install ejs
npm install uuid
Note: these additional libraries are not required by the Learnosity SDK. They are only required for the tutorial on this page.
Note that these manual installation methods are for development and testing only. For production use, you should install the SDK using the NPM package manager for Node.js, as described above.
Let's take a look at a simple example of the SDK in action. In this example, we'll load an assessment into the browser.
To start up your Node.js web server, first find the following folder location under the SDK. Change directory ('cd') to this location on the command line.
.../learnosity-sdk-nodejs/docs/quickstart/assessment/
To start, run this command from that folder:
npm run start-standalone-assessment
From this point on, we'll assume that your web server is available at this local address (it will report the port being used when you launch it, by default it is port 3000):
When you open this URL with your browser, the page will load. This is a basic example of an assessment loaded into a web page with Learnosity's assessment player. You can interact with this demo assessment to try out the various Question types.
Let's walk through the code for this standalone assessment example. The source file is included under the quickstart folder, in this location:
.../learnosity-sdk-nodejs/docs/quickstart/assessment/standalone-assessment.js
The first section of code is JavaScript and is executed server-side. It constructs a set of configuration options for Items API, and securely signs them using the consumer key. The second section is HTML and JavaScript and is executed client-side, once the page is loaded in the browser. It renders and runs the assessment functionality.
We start by including the LearnositySDK constructor. This make it easy to generate and sign the config options.
const Learnosity = require('../../../index'); // Learnosity SDK constructor
Next, we declare the Learnosity consumer credentials we'll use to authorize this request. We also construct security settings that ensure the report is initialized on the intended domain. The value provided to the domain property must match the domain from which the file is actually served. The consumer key and consumer secret in this example are for Learnosity's public "demos" account (loaded from the config.js file). Once Learnosity provides your own consumer credentials, your Item bank and assessment data will be tied to your own consumer key and secret.
const config = require('../config'); // Load consumer key & secret
(of course, you should never normally put passwords into version control)
We bring in the UUID library.
const uuid = require('uuid'); // Load the UUID library
We also specify a few libraries to run a minimal web server, "Express.js" for the purposes of this example.
const express = require('express'); // Load Express.js web server
var app = express(); // Instantiate the web server
We also choose EJS as the view engine,
app.set('view engine', 'ejs'); // Set EJS as the templating language
Now we set up the user_id, session_id (both UUID values), and domain configuration.
const user_id = uuid.v4(); // Generate a UUID for the user ID
const session_id = uuid.v4(); // Generate a UUID for the session ID
const domain = 'localhost'; // Set the domain
Now we'll declare the Learnosity configuration options for Items API. These specify which assessment content should be rendered, how it should be displayed, which user is taking this assessment and how their responses should be stored.
app.get('/', function (req, res) {
const learnositySdk = new Learnosity(); // Instantiate the SDK
const request = learnositySdk.init( // Set Learnosity init options
'items', // Select Items API
{
consumer_key: config.consumerKey,
domain: 'localhost',
},
config.consumerSecret,
{
user_id: user_id,
activity_template_id: 'quickstart_examples_activity_template_001',
session_id: session_id,
activity_id: "quickstart_examples_activity_001",
rendering_type: 'assess',
type: 'submit_practice',
name: "Items API Quickstart",
state: 'initial',
config: {
regions: 'main'
}
}
);
user_id
: unique student identifier. Note: we never send or save student's names or other personally identifiable information in these requests. The unique identifier should be used to look up the entry in a database of students accessible within your system only. Learn more.activity_template_id
: reference of the Activity to retrieve from the Item bank. The Activity defines which Items will be served in this assessment.session_id
: uniquely identifies this specific assessment attempt for save/resume, data retrieval and reporting purposes. Here, we're using theUuid
helper to auto-generate a unique session id.activity_id
: a string you define, used solely for analytics to allow you run reporting and compare results of users submitting the same assessment.rendering_type
: selects a rendering mode,assess
mode is a "standalone" mode (loading a complete assessment player for navigation, as opposed toinline
for embedding without).type
: selects the context for the student response storage.submit_practice
mode means the student responses will be stored in the Learnosity cloud, allowing for grading and review.name
: human-friendly display name to be shown in reporting, via Reports API and Data API.state
: Optional. Can be set toinitial
,resume
orreview
.initial
is the default.
Note: you can submit the configuration options either as an array as shown above, or a JSON string.
In the example above, we're calling LearnositySDK's init()
constructor to construct our Items API configuration parameters, and signing them securely.
We've got our set of signed configuration parameters, so now we can set up our page content for output. The page can be as simple or as complex as needed, using your own HTML, JavaScript and your frameworks of choice to render the desired product experience.
This example uses HTML in an EJS template, served by the Express.js web server. However, the template used here can be easily modified for use in another framework.
The following example HTML template can be found in the standalone-assessment.ejs file.
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Learnosity SDK - NodeJS</title>
<script src="//items.learnosity.com/?latest-lts"></script>
</head>
<body>
<h1>Standalone Assessment Example</h1>
<div id="learnosity_assess"></div>
<script>
const request = <%- JSON.stringify(request) %>;
const itemsApp = LearnosityItems.init(request, {
readyListener() {
console.log('ready');
},
errorListener(err) {
console.log('error', err);
}
})
</script>
</body>
</html>
The important parts to be aware of in this HTML are:
- A div with
id="learnosity_assess"
. This is where the Learnosity assessment player will be rendered to deliver the assessment. - The
<script src="https://items.learnosity.com/?latest-lts"></script>
tag, which includes Learnosity's Items API on the page and makes the globalLearnosityItems
object available. The version specified aslatest-lts
will retrieve the latest version supported. To know more about switching to a specific LTS version, visit our Long Term Support (LTS) page. In production, you should always pin to a specific LTS version to ensure version compatibility. - The call to
LearnosityItems.init()
, which initiates Items API to inject the assessment player into the page. - The variable
request
dynamically sends the contents of our init options (Learnosity configuration) to JavaScript in the browser, so it can be passed toinit()
.
This marks the end of the quick start guide. From here, try modifying the example files yourself, you are welcome to use this code as a basis for your own projects. As mentioned earlier, the EJS template used here can be easily re-used in another framework.
Take a look at some more in-depth options and tutorials on using Learnosity assessment functionality below.
See a more detailed breakdown of all the SDK features, and examples of how to use more advanced or specialised features on the SDK reference page.
There are more quick start guides, going beyond the initial quick start topic of loading an assessment, these further tutorials show how to set up authoring and analytics:
- Authoring Items quick start guide (Author API) - create and edit new Questions and Items for your Item bank, then group your assessment Items into Activities, and
- Analytics / student reporting quick start guide (Reports API) - view the results and scores from an assessment Activity.
On our demo site, browse through many examples of Learnosity API integration. You can also download the entire demo site source code, the code for any single demo, or browse the codebase directly on GitHub.
See full documentation for Learnosity API init options, methods and events in the Learnosity reference site.
Find guidance on how to select a development pattern and arrange the architecture of your application with Learnosity, in the Technical Use-Cases Overview.
Get help deciding what application functionality to build yourself, or integrate off-the-shelf with the Learnosity "Golden Path" documentation.
Want more general information about how apps on Learnosity actually work? Take a look at our Key Learnosity Concepts page.
Need an explanation for the unique Learnosity meanings for Item, Activity and Item bank? See our Glossary of Learnosity-specific terms.
Contributions are welcome. See the contributing instructions page for more information. You can also get in touch via our support team.
The Learnosity Node.js SDK is licensed under an Apache 2.0 license. Read more.
Our SDKs include code to track the following information by adding it to the request being signed:
- SDK version
- SDK language
- SDK language version
- Host platform (OS)
- Platform version
We use this data to enable better support and feature planning.
Thanks for reading to the end! Find more information about developing an app with Learnosity on our documentation sites:
- help.learnosity.com -- general help portal and tutorials,
- reference.learnosity.com -- developer reference site, and
- authorguide.learnosity.com -- authoring documentation for content creators.