🧭
Compass-Edu
  • Compass-Edu Docs
  • Library
    • Compass
  • Tutorials
    • Basic Usage
  • Help
    • Common Errors & Issues
Powered by GitBook
On this page
  • Step One, Setting Up Your Enviroment:
  • Step Two, Installing Compass:
  • Step Three, Writing Some Code:
  • Step Four, Running It:

Was this helpful?

  1. Tutorials

Basic Usage

PreviousCompassNextCommon Errors & Issues

Last updated 5 years ago

Was this helpful?

In todays tutorial, we'll be Requiring, nstantiating and Logging in to Compass with Compass-Edu.

Step One, Setting Up Your Enviroment:

Create a folder, anywhere you like, and create a file inside it with the name index.js. Then, with your terminal, navigate to that directory (cd [The Folder Path]).

Step Two, Installing Compass:

Open your terminal of choice, and run npm install compass-edu. If this fails with a message such as npm: command not found, you most likely don't have NPM, or node for that matter installed. Head over to , and download the current LTS verson, then retry.

Step Three, Writing Some Code:

Open your index.js in your favourite Text Editor. Now, we're gonna get that Compass-Edu module you just installed. In node, to talk to modules, we say that the project requires it, so we type require(...), so lets do that.

const compassEdu = require('compass-edu');

const is a way of storing something, that can't be changed later on. Since we dont want to accidentally overwrite compassEdu, we're making it a const. compassEdu is just the name we give the library.

Now that we have the Compass-Edu library in our code, we can start talking to it.

Let's create an instance of , called user

const user = new compassEdu('school_prefix');

Here, we yet again use const's to create a user, which we set to an instance (we use new to create a new version of something) of Compass. We then give compass some information, our school_prefix, which you can read more about .

Now, we asked Compass to create a user, which can sometimes take a second as it connects to the compass website, so, lets wait until thats happened with the following:

user.on('initialized', async function(){

});

This code waits for the user to yell out (emit) "IM INITIALIZED!!!!!", which lets us know that its now safe to log in, so lets do that!

...async function() {
    
    await user.login({username: 'Compass Username', password: 'Compass Password'});
    
});

Here, replacing 'Compass Username' and 'Compass Password' with your actuall Compass details. Okay, lets break this down: await, asks the program to do something then awaits for it to finish. user.login, asks out user to login with the username and password we give it.

Now, just to test that all goes well, we're gonna add the following code, i'm not going to get into detaul on how it works for now, that'll come in a later tutorial.

    ...await user.login({...});
    
    console.table(await user.getClasses());

});

This will just spit out the classes for the user you provided.

Step Four, Running It:

Now we've got our code all done, let's try running it!

Head over to that terminal you had, inside your folder and run node index.js.

And bam! All your classes should've popped up. If not, make sure everythings typed correcly, and if errors still provail, check the page!

Common Errors & Issues
node's website
Compass
here