Meteor shell and es6: namespacing issue


I have a block in my code using NPM, therefore, it is required on the server.

* Basic idea of what is going on
* this needs Npm so it's on the server.
var fs = Npm.require('fs');
var net = Npm.require('net');

class Cylon {
  constructor(host='', port='8080') {
    this.connection = {
      host: host,
      port: port

    this.sockets = {};

  _connect(name) {
    this.sockets[name] = new net.Socket();

I then open meteor shell and try to use this.

> var cylon = new Cylon();
ReferenceError: Cylon is not defined

when using something on the client, you can use this “hack” to get around it

class MyClass { /** ... */ }
window.MyClass = MyClass;

Can you do similar on the server? How do you access the classes in the best way possible?


You can make the class global:

class CylonClass = {...}
Cylon = CylonClass;

Now Cylon is global.