How npm packages are run in browser without node? - node.js

I am using rusty_v8 to create a local runtime in my cargo project and I want to integrate an npm package into the v8 runtime I am using.
since npm packages need to node runtime. and node runtime is based on v8 correct me if I am wrong. how can I make it possible to run npm packages in my v8 runtime? or if I ask another way how does google chrome's v8 use node packages without using node in its runtime.

Related

Is there a difference between using npm and node.js?

I'm using npm to download libraries.
Is it correct to say that I'm using node.js ?
NPM is a package manager for Node.js packages, or modules.
NPM hosts thousands of free packages to download and use.
The NPM program is installed on your computer when you install Node.js
Node.js As an asynchronous event-driven JavaScript runtime, Node.js is designed to build scalable network applications.
https://nodejs.org/en/about/
Node.js is all about modularity, and with that comes the need for a quality package manager; for this purpose, npm was made. With npm comes the largest selection of community-created packages of any programming ecosystem, which makes building Node.js apps quick and easy.
https://nodejs.org/en/docs/meta/topics/dependencies/#npm
Hope I helped you see the differences.Best Regards !
Yes nodejs is a runtime environment for javascript docs here like JRE is for java. You can use Node to run javascript in you system otherwise you need a browser to run it
NPM is a library for javascript read here, you use that to install libraries incase you need to use some extra features you dont wanna code yourself
Nodejs can run w/o use of npm like you can use other library repo like yarn likewise you can use other run time environment like Deno and use npm with that w/o using node

Why does installing modules from NPM or Yarn depend on node?

I am using React (create-react-app)
My understanding of what happens when we install a package from NPM or Yarn is: It finds the module and clones the code into node_modules, modules can also have their own package.json and dependent modules are cloned recursively.
If we are using a purely client side app (like React in my case), why does install process depend on node version? Like I get jsdom#16.2.0: The engine "node" is incompatible with this module. Expected version ">=10". Got "9.11.2"
As newer versions of Node.js are released, new features are added and older features are deprecated. Libraries using these new features can decide to lock in the minimum Node.js version needed to use their library.
If you use the library with a lower version of Node.js, the library will probably not work.
If you're working on multiple projects that require different versions of Node.js, consider installing and using nvm. With nvm, you can switch between multiple versions as needed by your projects.
https://github.com/nvm-sh/nvm

How to run NPM using a specific Node interpreter?

I have an Electron project that uses native libraries, some of which have prebuilds that get downloaded during npm install. This grabs the prebuilds for the global Node version running NPM, which isn't quite what I need. Is there a way to execute NPM explicitly using the Electron binary in my project?

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

I don't know why the core modules in node js are not being recognized within my project using IntelliJ Idea (2016)

I keep getting the error: Cannot find module 'serve-favicon.' This error occurs not just for serve-favicon but for all core modules which also includes 'body-parser', 'cookie-parser', etc. I am using IntelliJ IDEA (version: 2016). I already enabled the Node.js Core library, and I have been able to use core modules in other projects successfully. What is different about this project however, is that I pulled it from github. Do I need to install another plugin? If yes, which one? Do I need to add another package?
serve-favicon, body-parser, cookie-parser are not node.js core modules.
You will need to install these dependencies from npm registry. To install these dependencies, you will need to run
npm install <package-name> --save
If you have pulled the project from github, chances are there will be a package.json file with a list of dependencies. In that case, all you need to do is run npm install from the project folder.

Resources