How to use NPM Package (Functions)

Hello everyone,

First off, I am a beginner to all this so please bear with me. I am having difficulty using a package that I found on NPM. I am trying to use some git commands within my Meteor application and am using this package:

https://www.npmjs.com/package/simple-git

On startup of my meteor application, I want to add a submodule if it does not already exist. So as the thread title mentions, how do I use this package? Compared to the examples, I have no idea how make it work.
Can I do something like this(?):

import { Meteor } from 'meteor/meteor';
import SimpleGit from 'simple-git';

Meteor.startup(() => {
	// code...
	SimpleGit.submoduleAdd('someRepo', '.');
});

Any help (or resources) would be great, thanks!

That should work. Checkout the guide: http://guide.meteor.com/using-npm-packages.html#using-npm

I have already read that and made as much sense of it as I could. Am I missing something? Thanks!

Its not clear for me too. I tried to use various client side libraries from npm but its not working out so far. I saw also saw few other question about how to use npm but didn’t see any answers that would clearly explain how to use npm libs.

I think the guide link is reasonable, but you probably want to start one section further up at Installing NPM packages first.

If you’re having particular problems, perhaps post the errors that you’re receiving.

1 Like

I haven’t used Simple Git but from the index.js source it looks like it’s exporting a function. The docs confirm this as well (using require syntax). So in your example your imported SimpleGit reference is really pointing to a function. So you could try something like:

import { Meteor } from 'meteor/meteor';
import simpleGit from 'simple-git';

const git = simpleGit();

Meteor.startup(() => {
  ...
  git.submoduleAdd('someRepo', '.');
});
3 Likes

Thanks a lot it works!! I was stuck on this and now I understand what was wrong.

1 Like