Install NodeJS package locally - node.js

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

Related

What's the difference between "npm install -g" (no args) and "npm link" to create CLI command?

To make a local node.js package work as a global commandline tool, I first add this to package.json
"bin": {
"myCommand": "./index.js"
}
According to the npm docs, I then have two options:
Within that folder, run npm install -g. According to the node docs:
npm install (in package directory, no arguments) ... In global mode
... installs the current package context (ie, the current working
directory) as a global package.
OR
Within that folder, run npm link. The node docs say
npm link in a package folder will create a symlink in the global
folder ... will also link any bins in the package to
{prefix}/bin/{name}
Both of these routes lets me run myCommand anywhere in the terminal while local edits are reflected in the tool without reinstalling/linking.
For local CLI tool purposes, these commands seem functionally identical. Is this true? Why would I want to use npm install -g (no args) when npm link seems functionally identical, plus affording extra capability?
Note: this question is purely about a local node project, nothing to do with anything in a remote package registry

Install global dependency manualy

I'm working on a project which is gonna be deployed on a VM(Windows OS) but I can't download dependencies because all npm ports are blocked and there is no way to open them.
So the only way to solve this is to zip all local dependencies and then copy them to the VM. This is pretty simple however I use two global dependencies: PM2 and pm2-windows-service.
My question is how to copy these two dependencies to the VM and then make them global ?
You can install global dependencies locally and use them from the node_modules path for example:
node node_modules/.bin/pm2 start app.js
instead of
pm2 start app.js
Actually I tend to recommend using the minimal amount of global dependencies ie. only npm
From npm-install:
npm install -g <tarball file>
And:
A package is:
a) a folder containing a program described by a package.json file
b) a gzipped tarball containing (a)
...
And also:
npm install <tarball file>:
Install a package that is sitting on the filesystem. Note: if you just
want to link a dev directory into your npm root, you can do this more
easily by using npm link.
Tarball requirements:
The filename must use .tar, .tar.gz, or .tgz as the extension.
The package contents should reside in a subfolder inside the tarball (usually it is called package/). npm strips one directory
layer when installing the package (an equivalent of tar x
--strip-components=1 is run).
The package must contain a package.json file with name and version properties.
Example:
npm install ./package.tgz
So just copy both (packed) packages and run the above command inside your VM, like npm i -g /pm2.tar.

npm start error nodejs

I give the command npm start. Terminal responds:
Make sure you are in correct directory when you run npm install, your current directory should have package.json file. for example based on the project you uploaded, you should be inside diplom folder and then run npm install.

npm install in a specific local folder

I'm currently trying to execute the command npm install to get all dependencies and modules necessary to run my package.json.
The problem is that I don't have Internet access to fetch from the internet, so I have downloaded the node_modules on a different PC and copy-paste it on my local folder that contains all. If I tried to run npm install without arguments, it's still trying to fetch from internet and fails.
I have read their documentation and apparently they have listed few npm install that takes different arguments, but still, I'm unable to install from the folder already downloaded.
I've tried to do npm install node_modules on the path that contains the package.json, but nothing. I'm running on windows 7.
If someone has an approach to specifying the local node_modules and just install all modules inside, I'll appreciate.
Thanks!
You probably should use npm-link...
From the docs:
Go to the node_modules directory, and, inside each package, run npm-link:
$ cd node_modules
$ cd package-name
$ npm link
$ cd ..
...
In the directory of your project which needs the local modules:
$ npm link package-name

npm install resulting in 'ENOENT: no such file or directory'

I've installed Node.js for Windows and I'm trying to install a package via npm. The command prompt is in the directory of the project (C:\Users\username\Desktop\NodeTest), which contains a single helloworld.js file. Upon typing 'npm install express', I receive the following error:
ENOENT: no such file or direcotry, open 'C:\Users\username\package.json
I'm attempting this from a clean install and cmd is running as admin.
Any ideas?
I was facing the same issue. I firstly delete my node_modules and delete the cache by following command:
rm -rf node_modules && npm cache clean --force
then I delete the package-lock.json file from my project and then hit npm install in command prompt and it works.
As already pointed out by Subburaj this is because you are missing a package.json.
Just run npm init to initialize that file for you; afterwards it should work.
If you are working on a Windows machine using Vagrant/VM, there's a chance that symlinks are the culprit for your problem. To determine if that is the case, simply copy your package.json and package-lock.json into a test directory that is not mounted/shared between OSs.
mkdir /tmp/symlinktest
cd {{your directory with your package*.json}}
cp package*.json /tmp/symlinktest
cd /tmp/symlinktest
npm install
If this results in a successful install, you'll need to either exclude the node_modules directory from the mount (there's various articles on doing this, however I can't say I've had success) or run npm install outside the mounted volume.
I deleted the package-lock.json and It worked for me.
Basically I was Offline while I tried to install with npm, so go online and try
npm install again
Check the project folder which you opened in microsoft visual code. Generally you are not in the right path so npm is not able to search the package.json ... My project was in Document/hostel/hostel .. I opened Document/hostel ... So npm tried to find the package.json in Documents folder .. When i entered one level inside to Document/hostel/hostel .. it was fixed.

Resources