DEV Community

Cover image for Meteor: a better way to use meteor npm command
Dragoș Străinu
Dragoș Străinu

Posted on • Edited on • Originally published at strdr4605.com

3 3

Meteor: a better way to use meteor npm command

Meteor advice to run meteor npm ... instead of npm ....

Using the meteor npm ... commands in place of traditional npm ... commands is particularly important when using Node.js modules that have binary dependencies that make native C calls (like bcrypt) because doing so ensures that they are built using the same libaries.

But if you are switching constantly between node projects (with/without meteor) sometimes you may forget to use meteor npm ... or use it in the wrong place.

Solution

We can create a bash function that will replace npm and run meteor npm ... if we have a .meteor folder in the project.

as all Meteor apps have a .meteor directory

Edit your shell config file with vim, nano, or vscode. Add this function at the end of the file.

# Add me to shell config file. ~/.zshrc or ~/.bashrc
ORIGINAL_NPM=$(which npm)
npm() {
  RED='\033[0;31m'
  GREEN='\033[0;92m'
  NC='\033[0m' # No Color
  if [[ -d .meteor ]]
  then
    echo "${RED}Meteor project${NC}\nRunning:\n\n\t${GREEN}meteor npm $@${NC}\n";
    meteor npm $@
  else
    eval $ORIGINAL_NPM $@
  fi
}
Enter fullscreen mode Exit fullscreen mode

If needed we can also add another function for meteor node.

See more posts on https://strdr4605.com/

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay