When trying to run the command "npm {package} --save-dev" in the terminal, it

I attempted to execute the following commands:

$npm install mocha --save-dev 

and then

$mocha

However, I received this error message:

$-bash: mocha: command not found

If I install it globally, it works. But is there a way to use a specific package version for this project only without installing it globally?

I am using a Mac with OS 10.11 El Capitan.

Answer №1

One way to execute local dependencies is by utilizing the npx command.

To test this out, run the following command:

 npx jest

Answer №2

If you haven't set up mocha globally, you'll need to direct the terminal to your project's local directory

Try running this command instead:

./node_modules/.bin/mocha

This will execute the version of mocha that is locally installed within your project.

Answer №3

In order to utilize a command that is part of an NPM package, the global installation is necessary. You can achieve this by executing the following:

$ npm i -g mocha

If you prefer not to install it globally, an alternative is to use the local mocha command available at:

$ <app>/node_modules/.bin/mocha

Answer №4

$ navigate to the project_directory

If you have already listed the dependency in package.json file, then proceed with the following steps:

$ npm install

$ ./node_modules/.bin/<module-name> -V // to check the version
$ ./node_modules/.bin/<module-name> <action> // to utilize the module

In case you wish to add a new module, begin by executing:

$ npm install <module-name> --save-dev

Then, follow the commands to retrieve the version and implement the module. By doing this, you can configure and apply specific node_modules for a particular project, enhancing organization and sharing capabilities. For global installations of modules, run ->

$ npm install -g <module-name>

Alternatively, use sudo privileges as follows ->

$ sudo npm install -g <module-name>

I trust this information proves helpful :) :)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What causes the tweets' IDs to be altered by axios when parsing the response from the Twitter search API?

I am currently utilizing axios to send a GET request to the Twitter search API in order to fetch recent tweets that utilize a specific hashtag. To begin with, I ran tests on the twitter search API via Postman and noticed that the id and id_str tweet statu ...

Optimizing Materialize-css, Laravel, and VueJS integration: best practices for setting up modals, side-nav, and

Currently, I am in the process of constructing a website utilizing Laravel 5.4, Laravel Mix, VueJS, and Materialize-css. Fortunately, VueJS and jQuery are already integrated with Laravel, so no additional setup is required in that regard. All custom compo ...

Is there a way to edit this flake.nix file to avoid having to reload the nix package each time the environment is loaded?

This post from John's blog (https://johns.codes/blog/building-typescript-node-apps-with-nix) serves as an example for my current question. I am trying to set up a development environment with an npm package that does not have a Nix equivalent. I feel ...

The request from localhost:3000 to localhost:3003 could not be proxied by ReactJS

Currently, I am working on developing a Single Page Application (SPA) using create-react-app with an expressjs server as the backend. During development, my frontend test server runs on port 3000 while my backend expressjs test server runs on port 3003. T ...

Converting Callbacks to Promises in Node.js

I am facing a challenge with my node js application as I am attempting to promisify multiple callback functions without success. It has reached a point where I am unsure if it is even feasible. If you can assist me in promisifying the code provided below, ...

Guide on programmatically setting up nvm and utilizing npm

Hey there! I've been working on some scripts to customize my shell environment, and everything is going great except for nvm. Here's a snippet from my script: #!/bin/zsh set -Eeuo pipefail echo 'Installing nvm' touch $HOME/.zshrc curl ...

Issue: Unable to resolve the address 127.0.0.1 - Windows 32-bit operating system - Node version 6.11.2

Launching a server using the script below (arranca_server.sh) # Start Node server export NODE_ENV=development-course export NODE_PORT=9001 export NODE_HOST=127.0.0.1 node server Upon running the script, Node returns: > events.js:160 > ...

Azure deployment for Angular app was unsuccessful due to npm startup failure

I've been trying to deploy my Angular application on Azure. While I can successfully publish it using Azure, I keep encountering an error message when trying to access the published site: AggregateException: One or more errors occurred. (One or more ...

What are the steps to set up a MEVN project to run on an intranet using nginx?

As a newcomer to the world of Vue, Node, Express, and MongoDB API while using Nginx, I have a question about where to place the port configuration. Can anyone provide insight on this? My project consists of a "client" folder and a "server" folder, both co ...

How does the use of nodejs, a server-side scripting language, tie into ReactJs or other front-end languages?

Can Node, being a server-side scripting language, be effectively utilized in the development of front-end applications such as npx create-react-app or npx create-nuxt-app? ...

Mastering the art of managing promises within nested loops

Embarking on my Promise journey, I find myself faced with a scenario where a list of objects within another list of objects needs to be updated based on responses from an external API. I've attempted to simulate the scenario below. The code snippet f ...

The Art of Structuring MongoDB Schema

I have been diving into MongoDB through their online Webinar hosted on their platform and I am currently working on connecting Products to a Category (for example, associating iPhones with the Mobiles Category which falls under Electronics). However, as I ...

The NPM update command encountered numerous warnings but ultimately completed successfully

Recently, I dove into the world of NPM packages and encountered some issues with dependencies. Fortunately, this community provided great assistance in resolving them. However, a new challenge arose when attempting to update the CLI application. Interestin ...

Unable to get i18next functioning in my Node.js Express backend

I'm currently facing difficulties in implementing localization for my nodeJS backend. Within my Angular frontend, I have a language-setting interceptor that successfully sets the language in the request header. You can refer to the image below which ...

Unable to add npm package at this time

Feeling a bit desperate right now. I recently implemented npm and grunt to enhance my development process, which was working smoothly until today. Suddenly, I'm unable to install npm packages and keep encountering the following error message: 0 info ...

Unexpected errors are encountered when using ng serve

When I run the ng serve command, unexpected errors are occurring on my system. The errors include: PS C:\Users\SAYED-SADAT\Desktop\data\coding\itsm-frontend\itsm-frontend> ng serveYour global Angular CLI version (13.0 ...

Having difficulty adding a custom library from a repository into an Ember project as a dependency

I've been working on a WebGL library that I want to include as a dependency in an EmberJS project. It seems like I should be able to do this directly from the repository without creating an npm package, but I'm running into some issues. To illus ...

Here's a unique version: "Sharing data between functions in the Express GET API within MEAN Stack"

Within my code, I have a function called hsResponse which operates as described below. When I run this function independently, I am able to see the expected body response in the console log. Now, I would like to incorporate this hsResponse function within ...

Convert the existing JavaScript code to TypeScript in order to resolve the implicit error

I'm currently working on my initial React project using Typescript, but I've hit a snag with the code snippet below. An error message is popping up - Parameter 'name' implicitly has an 'any' type.ts(7006) Here is the complet ...

Combine several items to form a single entity

When I have two objects returned from the database, my goal is to combine them into one object. Here are the examples: { "id": 4, "first_name": "s", "last_name": "a", ...