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"); | |
}); |
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"); |
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"}); | |
//... |
Afterwards you can proceed as before and outlined in the post referred above.
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
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
Brill – thanks Dirk. I’ve been banging my head against a brick wall on this one!
Sorry I am really struggling with importing data into Meteor.Collection. I do not know where exactly I must declare and use Fiber, Meteor.bindEnvironment, Future, to make my code run correctly http://pastebin.com/V6JvUPaY
got sorted sorry