From the course: SharePoint Framework for Developers: 1 Understanding the Toolchain

An introduction to Node.js and npm

From the course: SharePoint Framework for Developers: 1 Understanding the Toolchain

Start my 1-month free trial

An introduction to Node.js and npm

- [Instructor] Over the past few years, one of the most important dev platforms that has emerged is Node.js and npm-based development. Certainly Sharepoint Framework is another example of that kind of development methodology. So let's understand what is Node.js and npm, Node Package Manager? Javascript engines have improved in performance by a lot. Imagine a hundred times, thousand times, or even a million times, depending upon what you're doing. In fact, their performance rivals and many times outstrips other languages like C#; it's amazing. So some smart people saw opportunity there and they figured, "Why should such an amazing execution engine "be only tied to the browser?" The removed the browser portion from it and gave us a server-side execution engine called Node.js. So again, it has a number of things built into it. Debugger, streaming, ability to make SCTP calls right to the console, or most importantly, be able to work with modules. So a lot of reusable code can be done on top of these things that come with Node.js. And the way you manage those modules is with npm. In fact, npm itself is a module; it's a node module. It stands for Node Package Manager. It is the node module that you use to manage other node modules. The way this works is that a developer would write some valuable reusable code and they would publish it to an npm repository. This npm repository may be public, in other words you wish to share this code with the entire world, or it may be private. Either way, you have the ability to reuse this code across the entire world or just within your team or within a few teams. Standing on the shoulders of others, reusable code. That's one of the main tenants of node-based development. You may not know how to target, say, airplay on a Mac, or some other arcane capability, but through npm and node modules you can do most of commonly asked things. Like tapping into Bluetooth, there's an npm module for that. So you use code from people outside of your organization or maybe even inside. You can browse for these packages or node modules on npmjs.org or you can download then directly from GitHub or other source control repos. You can also have private node modules coming from these source control repos, or from tar walls or FTP locations. And there is a concept of semantic versioning built into your packages, because let's be honest, these days things are moving so fast, staying on top of the right versions is very important, not just from a functionality point of view, but also from a security point of view. So that also has been thought through in node based modules and this reusable code concept. Another word that you will hear a lot in this node based development is package.json. Every node based project has a package.json. It is sort of the introduction of your project. It documents your node module or project, provides a version It tells what script it supports, what things it depends on, what are the things that it depends on only during dev time, what is the GitHub repo, and so on and so forth. So typically speaking, a node module would have at least some reusable code, maybe more than one file, and a package.json. The package.json tells you what is the entry point, in other words what is the index.js for that reusable code module. There's things like web pack, etc. that rely on this standard. And then there is the concept of semantic versioning. Semantic versioning is A dot B dot C. Every node module has a semantic version, the idea being that if you change the number six, for instance, the patch, that means that people should feel free to upgrade to a newer version with confidence that nothing will break. A minor version means that maybe new features have been introduced, a new method, for instance, but it won't break the API; existing methods did not change. But a major version generally has the liberty of breaking the API. We'll see all of these in practice in examples very soon. But with this basic introduction to the theory of node based development, now let's look at node based development in action through demos.

Contents