Meteor With Tedious From Npm

This post is meant as an update to my previous post regarding the access of an MSSQL database from your Meteor app. Version 0.6.0 of Meteor simplifies the inclusion of Npm modules, utilizing Meteors own package mechanism. You cannot directly include Npm modules in your app, though. You have to take the little detour of defining a private package. Well that sounds difficult. But it’s not. Here are the command line steps:

cd [YOUR METEOR APP FOLDER]
mkdir packages
cd packages
mkdir tedious
cd tedious
touch package.js
kate package.js

In your app directory create a folder with the name: “packages”, if it doesn’t exist already. Change into it and create a folder for the Npm module you like to include. I made a “tedious” folder. Again change into it and create a single file with the name: “package.js” there. Open the file with your favorite editor and define the package in the following way:

Package.describe({
summary: "Tedious lib to access MS SQL databases."
});
Npm.depends({"tedious": "0.1.3"});
Package.on_use(function (api) {
api.add_files("load_tedious.js","server");
});
view raw package.js hosted with ❤ by GitHub

To actually use tedious in the rest of the app, you have to provide a way to access it. You can do this by adding a variable to the global scope. Unfortunately you have to do this in a separate file. Add a file:

touch load_tedious.js
kate load_tedious.js

And put the following content in it:

tedious = Npm.require("tedious");
view raw load_tedious.js hosted with ❤ by GitHub

When you start your Meteor app, it will pull tedious and all of its dependencies from Npm. Now you can access tedious by simply using the variable name. For example this way:

//...
con = tedious.Connection({server: "server", userName: "user", password: "pw"});
//...
view raw gistfile1.js hosted with ❤ by GitHub

Afterwards you can proceed as before and outlined in the post referred above.

7 thoughts on “Meteor With Tedious From Npm

  1. jasonratcliffe says:

    Hi Shiggy,

    It looks like the pictures of what you’re entering into package.js and load_tedious.js are missing – is there any chance you could fix this post please?

    Thanks,

    Jason

    1. Dirk Porsche says:

      Hi Jason,

      WordPress.com recently changed the way on how to include Github gists. And I haven’t caught up updating all posts. I did just that for the post you requested.

      Kind regards,
      Dirk

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.