I have following project structure:
-app
-client
-server
I need to run npm install from server folder (i have build script)
So i running
npm --prefix "../client" install
But instead of going to parent folder, npm creating folder with .. name and client inside. And trying to run npm install there. And installation fails because package.json is not there.
On linux its working fine.
How can i define relative path from parent folder ?
Related
Created new folder and did npm install serve in it.
It created package-lock.json and node_modules/ folder.
When I run in the same folder serve it shows error:
command not found: serve
What is the way to install?
I am using: npm#6.5.0
My dev environment is MACOS
I read a great many pages on this topic and nothing worked until I tried the following
./node_modules/.bin/serve -s build
Also if you are using VS CODE you may want to bring up the terminal window outside of VS CODE - this seems to have snared a lot of people.
First of all, you should start your project running
npm init
This will create the package.json file.
Then, you can install the serve package globally.
npm install -g serve
And now you can run serve.
The serve binary was not found because the operating system cannot locate it in the PATH environment variable.
When you do the npm install serve command. The serve module is only installed into the node_modules directory found under the the project folder. Unless you explicitly include the absolute path of this node_module directory as part of your PATH env var, the OS won't know where to find serve.
Like others say, the typical practise would be to install the module using the -g flag. G means global.
When -g is used, npm will put the binary in its node directory somewhere and this this directory would have been included as part of your PATH when you install node, thus making the any new binary discoverable.
If the node.js module has a "command" and you want to run it without installing the module globally(npm install -g serve). You can run it like ./node-modules/.bin/command from the root folder of the project.
Now, what is generally used is npx, so that you can from within a project easily run any of the binaries within its local node_modules or your system's global node_modules/ and any other commands on the $PATH.
For example, here we install webpack as a local dependency. You can image doing this in a folder after running npm init. Then we run webpack without having to worry about referencing the bin file:
$ npm i -D webpack
$ npx webpack
I would like npm ... to always run in the context of a subfolder of my project: "./assets".
When I run this command from the project root, it behaves as expected:
$ npm --prefix ./assets install
However, it does not read this from the .npmrc in the root folder.
$ echo "prefix=./assets" > .npmrc
$ npm i
# creates an empty ./node_modules folder
How can I set a set project specific default prefix for npm commands?
If you have install npm globally you can simply configure prefix to set for specific folder so that you can install other node modules to that folder. Following is the command to set prefix.
npm config set prefix /Programming/node-v0.10.31-linux-x64/
here i have configure Node in node-v0.10.31-linux-x64 this folder and node modules will be install there.
or
if you want to install node modules for specific folder individually you can user following command
npm install bower -g --prefix /Programming/node-v0.10.31-linux-x64/
I'm building a .NET Web Application and using NodeJS for a bunch of build tasks (minification, bundling, unit tests, etc).
My problem is that when I run the following from my source code folder:
npm install -g
It not only checks and installs all of the node packages (great!) .. but it also copies the ENTIRE source code folder over to my global node_modules folder (.cs, .sln, bin folders .. the lot ... not so great!)
Is there any way of stopping it from doing this?
Note - I've redirected the npm and cache folders to a separate path using:
npm config set prefix e:\npm-repo\npm --global
npm config set cache e:\npm-repo\cache --global
This is how npm install -g works.
You can try npm install if you want to install only the dependencies from package.json locally.
When i try to install package on my local directory using npm install connect,but it just keep pop up some warning about
no such file or directory, open '/Users/felixfong/package.json'
But i don't not want to install package at my computer directory,i want to install at my local web app directory
Are you sure you are inside your local web app directory when you run the npm install connect command?
cd app-directory/
npm install connect
Also ensure that a package.json file is also present in the app-directory.
If it isn't present, you can use npm init command to create the package.json file interactively.
You have to go inside your project directory using
Then you can check package.json.
If package.json file is not there then initialize npm using the following command:
npm init
Then your can install the package using the following command:
npm install connect
'npm install connect' does not save the connect npm package in package.json file.
For saving the package into package.json file you have to givt --save option like:
npm install connect --save
Make sure that you are in web app's directory. Current path can be checked via command pwd in Linux and cd in windows. Navigate to your web app directory if you are somewhere else. Check existence of package.json by listing the content of the folder. ls and dir can be used for ubuntu and windows respectively for listing content. Commands for ubuntu are as below:
pwd
cd your-path/
ls
Now Initialize npm in your web app directory if package.json is not already existing there.
npm init
This will ask some information like:
name of the app,
its version,
description,
entry point,
test command,
git repo,
keywords,
author and
license (if any)
You can select default values by leaving the fields empty if you aren't sure or confused about any field. Combining this information as json, npm will create a file named package.json
Just run the desired command now after initialization of npm or if its already initialized:
npm install connect
I have gulpfile.js in one directory and node_modules in another.
When I run gulp, i get the error -
'Local gulp not found in '..(the directory)..
Try running: npm install gulp'
The thing is - I cannot install gulp in the directory of gulpfile.js and so I need a way to tell the gulp to refere to the other directory i have gulp installed in.
You don't need to install gulp globally if you don't want to. What you can do is run your gulp executable (from your node_modules) and then pass in the location of your gulpfile using the --gulpfile parameter. Also, if you want to control where your gulp is running, make use of the --cwd parameter.
Here's an example:
<NODE_MODULES DIR>/gulp/bin/gulp.js --gulpfile <GULP FILE> --cwd <SOME DIR>
There is no need to install gulp globally.
First install gulp (ideally on dev dependencies)
npm install gulp --save-dev
Then in the package.json add the line you want to run
"scripts" : {
"gulp" : "gulp"}
}
Finally in the command line use
npm run gulp
npm will use the binary from the node modules without any need to install it globally or to write down the whole path
You need to install gulp globally:
npm install -g gulp
This will allow you to run gulp from the command line in any directory.
Put the node_modules folder in parent directory always, then make project directory as child/grandchild folder.
Don't put the node_modules folder in any child directory
Folder structure will be like:
parent
└──node_modules
└─project_1
└─project_2
In any child/grand child directory gulp will work