What is the npm tmp directory? Can I delete it? - node.js

On a brand new Ubuntu machine 12.04.3 I did the following installations on my home directory:
Git: sudo apt-get install git
Node.js: sudo apt-get install nodejs and updated it with sudo npm cache clean -f, sudo npm install -g n, sudo n stable
npm: sudo apt-get install npm and then updated it with npm update npm -g
Yoeman: sudo npm install -g yo
A new "tmp" directory popped up in my home directory with the following structure:
npm-13728-uErqEQ4O:
1392566713336-0.9297236264683306 1392566726706-0.4921755278483033
npm-13763-yoMEDYdC:
1392566864990-0.09957328205928206
Each of the uErqEQ4O subdirectories contain:
tmp.tgz
package:
AUTHORS configure html make.bat node_modules scripts
bin CONTRIBUTING.md lib Makefile package.json test
cli.js doc LICENSE man README.md
The yoMEDYdC subdirectory contains:
tmp.tgz
package:
cli.js package.json readme.md scripts yeoman.txt yoyo.js
What is this tmp npm directory and everything inside it? Why was it generated?
Can I delete it? If not, where can I move it to because I don't want it in my home directory?

Tmp or temp generally means some kind of temporary storage, which is auto generated by program (mostly per one session):
Here is what the npm tmp directory is:
Temporary files are stored by default in the folder specified by the
tmp config, which defaults to the TMPDIR, TMP, or TEMP environment
variables, or /tmp on Unix and c:\windows\temp on Windows.
Temp files are given a unique folder under this root for each run of
the program, and are deleted upon successful exit.
If you are not sure can you delete it, just add some prefix to it e.g. _tmp and try to run you app. If it runs with prefix then you can delete it. If not, then you app has some kind of reference to it.

Related

Can I install packages from the node_modules directory?

So a friend has sent me his node_modules directory but I don't want to manually type npm i *package* for each package and I don't have the package.json file to npm install from.
Is there a possible way to install the packages in the node_modules directory via terminal?
It is a very backwards scenario, I'm just curious if there's a way...
You can running:
npm ls -json > tree.json
node -e "console.log(Object.entries(require('./tree.json').dependencies).map(([m, v])=>m+'#'+v.version))"
It will print
[ 'fastify#2.13.0', 'fastify-url-data#2.4.0', 'pino-pretty#3.6.1' ]
for my test

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

Install NodeJS package 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

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.

Running npm install using custom nodejs installation

I have 2 nodejs installation v0.8.18 ( executable name is node) and v0.10.20 (executable name is nodejs) in my ubuntu 12.04 system.
when I running npm install how can I specify npm use the executable named "nodejs" instead of "node"
If you in-fact actually want to toggle between various nodejs releases, there is an environment variable NODE_PATH which controls the directory path node uses to reach modules. The other issue is the env var PATH which the unix uses to reach executables, IE. node and npm
Additionally, node/npm uses these dirs/files :
~/.npmrc
~/.npm
~/tmp
~/.npm-init.js
those may or may not be impacted by different releases of node.
If you install each release from source code you have full control of NODE_PATH and PATH
source code for all releases available at http://nodejs.org/dist/
Below are the steps to install a given release from source
NOTE - this installs nodejs which gives you both node as well as npm, they come together per release.
to start fresh remove prior node.js and npm installs as well as these :
sudo mv ~/.npmrc ~/.npmrc_ignore
sudo mv ~/.npm ~/.npm_ignore
sudo mv ~/tmp ~/tmp_ignore
sudo mv ~/.npm-init.js ~/.npm-init.js_ignore
to install nodejs and npm as yourself NOT root do these commands (OSX/linux) :
parent_dir=${HOME}/bin_xxxx # replace bin_xxx with something specific
# to node release like bin_v0.10.31
mkdir ${parent_dir}
download source from : http://nodejs.org/download/
cd node-v0.xxxx
./configure --prefix=${parent_dir}/nodejs
make -j8
make install
which puts it into dir defined by above --prefix
export PATH=${parent_dir}/nodejs/bin:$PATH
define environment variable NODE_PATH so node can find dir for modules otherwise
npm install xxx will put newly installed module into dir in curr dir :
export NODE_PATH=${parent_dir}/nodejs/lib/node_modules
do above AND use syntax : npm install -g some_cool_module
always use the -g for global so it gets installed into dir $NODE_PATH
and not your $PWD
nodejs install gives you npm as well :
ls -la ${parent_dir}/nodejs/bin

Resources