copying node_modules to offline computer - node.js

I need to copy a Node.JS project to a computer that will not be connected to the internet. Yes, I know that NPM can create a TarBall, but that is really not appropriate here:
It is a windows box
It has limited storage
I was wondering if I could just do a recursive copy of all the .js files in node_modules
[NOTE, my node project is very clean, it does not include any .dll or native system access stuff]
E.g.
robocopy $source/node_modules $dest/node_modules /S /NFL /TEE /LOG:watson.log /MT:16 *.js *.json *.types
which uses 16 threads in RoboCopy to do a full tree copy
#robocopy swtiches /S = subdirs, /ETA = estimates, /NFL = don't list files, /MT = number of parallel tasks, /TEE show log on console
#robocopy switches /xd directory exclude /xf file exclude

I found this is working for me. But then, I did not need any fancy dependencies (e.g. DLL files). Works fine at removing lots of stuff in the packages I do not need.

Related

How to install node.js in a custom directory through powershell?

I am making a script to install NodeJS on several machines through PowerShell.
By default NodeJS gets installed in C:\Program Files\nodejs folder. Can I define a custom directory for the installation?
I am running this command:
msiexec.exe /i $nodejs_download_filename /L*V "logger.log" /passive | out-null
Is there any argument to add to this line in order to specify the target directory instead of the default one?
You can refer this
Install Node.js on a different hard drive from C to D
You can move the node.exe to the d drive. Then check your environment path.
Type set in a command window or in computer properties.
Make sure you have the folder that contains node.exe in your path.
Running node in a command window will work from any folder then.
For installed npm packages, ie.. node_modules folder..
That just needs to be in a directory above where your writing your code, so try putting that folder in d:\ Assuming your going to be writing your apps on the d drive now.
In .npmrc file, change prefix setting to desired folder. Global packages get installed in node_modules under that folder.

Node on Windows error: "Source Path Too Long"

Explanation :
There are about 15 subfolders in the node_modules directory. When going to perform any operation (deleted, moved or renamed) it popup below message.
Error message:
The source file name(s) are larger than is supported by the file
system. Try moving to a location which has a shorter path name, or try
renaming to shorter name(s) before attempting this operation.
Screenshot :
sub folder inside npm_modules directory.
node_modules\gulp-connect\node_modules\gulp-util\node_modules\dateformat\node_modules\meow\node_modules\normalize-package-data\node_modules\validate-npm-package-license\node_modules\spdx-expression-parse\node_modules\spdx-license-ids\spdx-license-ids.json
Tried so far:
I also tried to delete the folder (node_modules) using command prompt using command rmdir <dirname> /S but did not work as well.
There is a way to do this is that go into subfolder after subfolder, renaming each folder to something short like 'b'. Eventually the path is short enough to allow deletion. This will waste quite a bit of time.
Is there any efficient way to delete this node_modules directory?
Newest versions of npm fix this issue flattening the path: https://github.com/npm/npm/issues/3697.
Try
D:\vms\fe> robocopy d:\path\to\temp\dir node_modules /purge
to remove the nested dirs.
Update
As pointed by Coding Professor, another option is use rimraf util (which basically calls rm -rf):
> npm install -g rimraf
> rimraf node_modules
For the record, and because of the release of a newish open-source project released by Microsoft, you can easily delete paths that are too long using WinFile (which was introduced in WinXP).
Sometimes you have to go "Back to the Future". This can delete paths too long on Microsoft networks share as well.
WinFile (compiled for Win10) available here https://github.com/Microsoft/winfile
To find many paths that are too long and automate a fix, I recommend Path Too Long Auto Fixer - a free demo is available.

node.js node-modules' file path too long

I want to start learning node.js from Lynda.com "Node.js Essential Training", but I cannot extract the exercises files' "node-modules" folder for chapters 09_03 and 11_06.
I get for example this:
! C:\no\e.zip: Cannot create folder Ex_Files_Nodejs_EssT\Exercise Files\Ch11\11_06\start\node_modules\grunt-contrib-jshint\node_modules\jshint\node_modules\htmlparser2\node_modules\domutils\node_modules\dom-serializer\node_modules\entities\maps
! The filename or extension is too long.
! C:\no\e.zip: Cannot create Ex_Files_Nodejs_EssT\Exercise Files\Ch11\11_06\start\node_modules\grunt-contrib-jshint\node_modules\jshint\node_modules\htmlparser2\node_modules\domutils\node_modules\dom-serializer\node_modules\entities\maps\legacy.json
Total path and file name length must not exceed 260 characters
! The system cannot find the path specified.
How will I be able to make those exercises if I cannot extract the files?
Can you extract them without the node_modules/ folder?
You don't have to extract the installed dependencies. Instead, there should be a package.json file and then you can install them by running npm install command (from cmd or git bash terminal).
Check also that you're running version 3 of NPM (npm --version). Then all dependencies will be installed flat (not nesting node_modules/) and that won't cause your issue.
Try using a file extraction program like WinZip or 7Zip. It should allow you to redirect the extraction of certain files or folders to another location.

NodeJS archive manager

I need to get the content of archives and then I want to uncompress the selected one - but I dont want to uncompress the archives to know what's in it. I'd like to list and uncompress at least zip and rar, but (if that's possible) I don't want to be limited to only these two.
Can you advise good npm modules or other projects to achieve this?
Here's what I came up with:
zip
I found node-zip can only unzip files, but not list archive content.
rar
The best solution seems node-rar, but I can't install it on Windows.
node-uncompress This does what it says: It's an "Command-line wrapper for uncompressing various file types." So there is again no possibility to list archive content.
Currently I try to get node-uncompress to list files and hopefully it must never run cross-platform.
Solution:
I am now using 7zip with the node module node-7z instead of trying to get every archive working on its own. The corresponding site is: https://www.npmjs.com/package/node-7z
This library uses the OS independent archive manager 7zip. On Windows 7za is used. "7za.exe (a = alone) is a standalone version of 7-Zip". I've tested it on Windows and Ubuntu and it works great.
Update:
At Windows: Somehow I just got it working by adding 7za to the Path variables - not by adding 7za.exe to the "the same directory of your package.json file." like the description says.
Update 2:
On Windows 7za, that's referred in the node-7z post, cannot handle .rar-archives. So I'm using the "casual" 7-zip instead of 7za.exe. I just renamed the commanline 7z.exe to 7za.exe and added the 7-zip folder to the Path Variables.

Install Node.js on a different hard drive from C to D

I have node and npm with existing packages currently installed to the C drive on Windows. My C drive is an SSD with a low amount of space. How can I move the node installation to a different drive? Would I need to reinstall node and all packages? The current node installer doesn't seem to specify drives.
You can move the node.exe to the d drive. Then check your environment path. Type set in a command window or in computer properties. Make sure you have the folder that contains node.exe in your path. Running node in a command window will work from any folder then.
For installed npm packages, ie.. node_modules folder.. That just needs to be in a directory above where your writing your code, so try putting that folder in d:\ Assuming your going to be writing your apps on the d drive now.
In .npmrc file, change prefix setting to desired folder. Global packages get installed in node_modules under that folder
I'm not sure what you are talking about, the node installer has this page.
What version of node are you trying to install? This screenshot is taken from v0.11.7 of node.
I know this post was basically forever ago, but I found a much easier way than manipulating the path. Simply uninstall NPM using the npm uninstaller, reinstall on your other drive with a new folder called nodejs. It'll create the folder in there appropriately and npm will be successfully installed on you D drive.
Search -> Environmental variables of system
click on path ( both )
click on new
add the path of your node.exe file
boom you are done*
node -v to check

Resources