When looking to use NPM packages in my Meteor project, some research brings up this package:
https://github.com/arunoda/meteor-npm/
Basically you just npm install packages into the root folder of your meteor project and include then with:
var GithubApi = Meteor.require('github');
This is what I was doing and it was working fine on my localhost. Then I tried to upload to Meteors test server and it kept crashing because it could not load my async module using this method, which was working on my local. The problem was having the node_modules folder in the root directory, kept causing the app to crash on meteors servers. But in order to use Meteor.require to include the packages, that is where they have to be.
So I had to follow the instruction in this thread to fix the issue:
How can I deploy node modules in a Meteor app on meteor.com?
This method requires me to npm install the package into the /public folder. Then I have to use the following code to include the package:
path = Npm.require("path")
fs = Npm.require("fs")
base = path.resolve(".")
isBundle = fs.existsSync(base + "/bundle")
modulePath = base + ((if isBundle then "/bundle/static" else "/../client/app")) + "/node_modules/"
async = Npm.require(modulePath + "async")
The thread is from 2012 so I am wondering what is the current best practice for including NPM modules on the server?
I can include npm modules on the client by including a bundle.js browserified file in the client directory, so that problem is solved for me, but what is the best way for npm use server side?