Why does "npm install" require Node.js preinstalled in the system? - node.js

I've recently started Tailwind CSS where I've to install Tailwind into my system, not knowing the fact that my system has to contain Node.js preinstalled in my system I proceeded to paste npm install -D tailwindcss postcss autoprefixer in the terminal but it threw so many errors. After some research, I found about Node.js. Though my problem is solved I want to know why it happened.

The reason it needs nodejs is as simple as, you need to have a nodejs to have/use the npm. Nothing more than that.
Diving into what you are doing here: By running npm install tailwind, you are installing a node package called tailwind with a package management tool called npm. Nodejs is the javascript environment that gonna execute it later when you use it
Think of the the relationshipi between pip and python. When you try to install a python package, you use a python package manager called pip. What you are doing here is, you need tailwind css module, now you need node package manager (NPM) to have it download and work with nodejs.
Some furthur reading:
what is npm:
https://www.w3schools.com/whatis/whatis_npm.asp
Where your tailwind package come from:
https://docs.npmjs.com/about-npm

Related

NPM not installing node module

I have an angular project that comes with a package.json file and all the dependencies listed within, but each time I run "npm install", in the terminal, the packages appear to be downloading properly and a node module folder is created in my root folder, but at a certain stage the installation stops without an error message and the generated node module folder disappear from my project. please what do I do?
I can't reproduce your situation, somehow this may not fitable for you.
But I suggest re-install node.js to make sure npm install work correctly.
This link will help to find what version of node.js for you, based on you angular version.
Compatibility list for Angular/Angular-CLI and Node.js
Also, It would be good to manage node.js via NVM(Node Version Manager).

Can i use yarn instead of npm?

I'm super new to node and coding in general so please forgive me. I am trying to use weld scraping service, but I am using npm. To run, it says to use a yarn command: yarn dev # development . Is there a way I can run the same command with npm? I tried npm install dev # development, but it threw an error for the #. I tried downloading the contents of the repository first and then running, and got the same result. I tried researching what # means in yarn, or in terminal, and the only thing I found is in a shell script it shows that you are the superuser?
...Yarn can consume the same package.json format as npm, and can install any package from the npm registry.
https://classic.yarnpkg.com/en/docs/migrating-from-npm/
First of all Yarn is a package manager created by Facebook as an alternative to npm. It looks like the package you are trying to install can not be installed with npm. "npm install dev # development" will not work because it is not the format used by npm when you are trying to install some package. If the objective is to scrape a web site I recommend you to use some other popular npm packages as axios cheerio. You can use "npm install axios cheerio" to use them.

What is the difference between node.js runtime and npm package manager options while installing node.JS?

I am trying to install node.js by downloading the .exe file, I am confused and stuck on the Node.js setup where in it asks to install node.js runtime or npm package manager so I want to proceed through the installation after knowing fully the difference between the two.
My question is what is the difference between node.js runtime and npm
pacakage manager and what are all the features do I get on the two
options.
My basic purpose of installing node.js is to compile Typescript, Please help me to understand the features of the two package
First of all, it does not ask you to install Node.js runtime OR npm package manager, it offers you to install them both (if you want)
Now, Node.js runtime is basically what will understand your javascript code and execute it to produce a result.
Npm package manager is a tool which will allow you to install third party libraries (other people's code) by using the command line.
npm install express
will install the framework called express for example.
Node JS
Node.js is a platform built on Chrome's JavaScript runtime for easily
building fast, scalable network applications.
Real-Time services (Chat, Games etc)
NPM
Npm is a package manager. Typically this software is installed to
build Node applications.
It let's you install software (libraries, plugins, frameworks and
applications).
Node.js or Node is an open-source, cross-platform, JavaScript runtime environment(JSRE) that executes JavaScript code outside of a web browser.
npm is a package manager(like Nuget package manager in .NET -Microsoft ) for the JavaScript programming language. It is the default package manager for the JavaScript runtime environment Node.js.
You can differentiate them by finding their version using below code.
node --version
npm --version
node is a framework that can run JavaScript code on your machine while npm is a package manager. Using npm we can install and remove javascript packages also known as node modules. Now, it is not a rule that you should use npm to install and remove node modules. We can use yarn also. npm and yarn are capable of the following:
Read and understand package.json file
Download and put javascript modules in node_modules folder.
Run scripts mentioned in package.json such as starting a node server, running in dev and production mode, running scripts for unit testing etc.
npm by default run node server.js; if you didn't specify scripts in the package.json
"scripts": {
"start": "node your-script.js"
}
Which means npm run node
if you need use yarn, you'd better choose node.js runtime, usually the default choice is a better one for beginner //TAT

Do I need node.js to use UglifyJs2?

I'm trying to use the command line tools of UglifyJs to minify my files. On the git page it says to download it using npm: npm install uglify-js -g.
Is that the only way to download it? My website doesn't use node.js so I'm wondering if there's an alternate way.
You can download it directly from it's github repo. However, I do agree with JohnnyHK it's better to install via npm as it will handle any dependancies required by UglifyJS.
When installing a module using npm -g, you're installing a command-line utility that uses node.js for its run-time rather than a module for a node.js based web site.
So it's still easiest to use npm to install it.

Using NodeJS plugins in Electron

I am new to Electron (Atom-shell), and I am trying to load a NodeJS plugin into the application I am building, but I don't know how. The documentation is not clear on that.
For instance, I am trying to use sqlite3 plugin in my app, I used npm install sqlite3, and it was successfully installed. But the application throws and error when I try to call it var sqlite = require('sqlite3'). Are there any further steps I am not aware of ?
Thanks.
For pure JS (i.e. not native) modules you need the following:
Have the module listed in your package.json dependencies
Let electron know where to find the module (e.g. export NODE_PATH=/PATH/TO/node_module)
The first requirement is obvious and the second has its roots in this issue.
For native node modules (such as sqlite3) which use C++ bindings, you need to build them against electron headers to work. According to electron docs, the easiest way to do that would be:
npm install --save-dev electron-rebuild
# Every time you run npm install, run this
./node_modules/.bin/electron-rebuild
To install the npm modules correctly you should go into the folder of your electron app and install the module via npm.
npm install --save sqlite3
The flag --save is important, because npm will install the module inside your app.
Afterwards the require should work.

Resources