What is NPM and Node?

Asked

Viewed 8,678 times

23

The title of the question says it all. There are many articles about it, but in a clear and beginner way, what is NPM and what does it do? Like Node?

What they contribute to the construction of websites?

2 answers

31


Nodejs

Nodejs is a Runtime which allows the execution of Javascript code outside the browsers. It can be used inside other applications or even alone. It is an environment that functions as a virtual machine for the execution of scripts JS.

If you know PHP think it is both the language and its execution environment. It is a counterpoint to C# which is the language and the . NET is the execution environment. Nodejs is just the environment. Its language is Javascript. So think that Nodejs itself is the whole package of the environment.

Making another comparison is the JRE, IE, that Java package that you are required to install on your computer because of some software that needs and was done in Java (access bank sites, for example).

Web applications

It is widely used on the server side to meet the demands of web applications. There are some advantages in it, there are also disadvantages. But it’s usually just an option. Some choose because they have some need, others adopt because Javascript is the only language they know and do not want to use another that may be more suitable on the server side. In general it runs without a server. Something that today is common in other technologies, but it has the merit of demonstrating that this is not only feasible, but also desirable in various situations.

Perks

One of the advantages is a good event mechanism and non-blocking asynchronous execution. So it’s known to give great scalability. Something that other technologies can also.

Its success is due, in addition to allowing JS that people were already accustomed to, to the fact that the technologies usually had difficulty dealing with parallel operations and the sequential did not suit well. Especially PHP which is very much used on the server side is not good at this. People saw it as salvation.

It does not scale well for several processors (cores), at least it did not happen, I do not know how it is today.

It has a more extensive API than the JS has in a browser, can access database and files, for example. And of course if it doesn’t run in the browser it doesn’t make sense to have the Apis specific to it.

Currently it uses the V8 JS engine created by Google for Chrome which was the fastest at the time Nodejs was created, but the fastest is a transient feature. As far as I know, there’s nothing to stop one day being changed, even if I doubt it will happen, except for some serious reason, there’d be compatibility issues.

What they contribute to the construction of websites?

If you think of sites like the Nodejs client side, it doesn’t contribute anything. Actually it can be used on the server part, but it’s no different than using another environment/language.

NPM

NPM (Node Package Manager) is just a management package of JS code modules to install together with Nodejs and be able to use in your applications, or even your applications that need to be included with the Node.

Roughly it’s an installer taking care of the dependencies avoiding having to keep them close to your application and taking care of the updates. What does not always work as expected. In addition it is a module repository.

Deno

Now there is the Deno that is better than Node.

  • 2

    Excellent answer, but I would complement saying that NPM is still used to manage packages, within a development environment for example it controls the dependencies, within package json are informed the dependencies that it should install in the project. Thus avoiding committing external components to your project to your git repository by exemplifying.

  • 2

    @Felipepaetzold I improved on that

  • thank you very much.

12

Node

Node.js is a platform built on the engine JavaScript Chrome to easily build fast and scalable network applications. Node.js uses a non-blocking event-oriented I/O model that makes it lightweight and efficient, ideal for real-time applications with intense data exchange across distributed devices. Its goal is to help programmers create high-scalability applications (such as a web server), with code capable of manipulating tens of thousands of simultaneous connections, on a single physical machine.

How it works?

The Node runs in a JavaScript V8 VM. JavaScript on the server side can be a new concept for everyone who worked exclusively with Javascript on the client side. The Javascript V8 engine is the engine that Google uses with its Chrome browser. Few people think about what really happens with the JavaScript on client side. The engine JavaScript actually interprets the code and executes it. With V8 Google created an ultra-fast interpreter written in C++, with another unique aspect: you can download the engine and incorporate it into any desired application. This is not restricted in running in a browser. So Node currently uses the engine JavaScript V8 written by Google and proposes to be used on the server.

NPM

NPM is the reduced name of Node Package Manager (Node Package Manager). NPM is two things: First, and most importantly, it is an online repository for publishing open source projects for Node.js; second, it is a command line utility that interacts with this online repository, which helps in package installation, version management and dependency management..

From the version Node.js 0.5.x that NPM has been integrated into the installer of Node.js and this simplified the life of the developers, because before that there were several package managers for the Node.js.

It also maintains an online NPM repository that is also maintained by Joyent, currently it contains more than 30,000 modules open-source.

What does?

When you develop an application and decide to use a library, for example, the asynchronous Coalan Mcmahon library, you just need to use the command npm install async, and the specific module will be installed in the current directory inside the folder ./node_modules/. Once installed your folder node_modules, you will be able to use require() as if they were internal modules of your project.


Reference: Nodebr

Browser other questions tagged

You are not signed in. Login or sign up in order to post.