What is NodeJS
The beauty of NodeJS
A lot of modern web development frameworks are based od NodeJS, such as:
Asynchronous programming is a way of writing parallel programs in which a unit of work is running separately from the main thread and notifies the calling thread of its status. That status can be completion, progress or failure. So basically, the program’s code isn’t running linearly, but rather when it’s being “called” upon. A section of code doesn’t have to wait for a section before it to finish just because that section came first. This decreases code blocking significantly.
There are some packages that can help you deal with promises and asynchronous programming in general.
Understanding Node and NPM
NPM is a package manager for NodeJS used to download packages, manage versions, start projects and much more. NPM stands for Node Package Manager.
It’s the largest software package registry for open source code. It can be used to manage private development and it’s a preferred combination with NodeJS.
All packages are defined in package.json file that you can define with
Now you can install other packages and they’ll automatically be added to you package.json. You’ll also notice that when you do that, you’ll have a node modules folder created that will contain all your packages.
You can also check your nodeJS and NPM versions easily, like this.
Here is how the help is implemented in Node using NPM.
Here are some helpful NPM commands.
Your NodeJS project has dependencies and those are the packages that you’ve installed. But the deal is, those packages also have other packages as their dependencies. Not all of them, but some do, and that packages may also have their dependencies.
So the problem arises when your app is a few years old and some packages become deprecated and you have to replace them. That can become a real nightmare so it’s recommended to use as little packages as possible.
You can see that our express package has a lot of dependencies and above you can see two of them. Those 2 in particular don’t have any dependencies, but some of them might.
Starting with NodeJS
You can download NodeJS from the official site. If you’re running a Linux system, you can also download it through your terminal, like this.
Creating a HTTP server with Node
Here’s the simplest way to create a HTTP server and start it. It requires only a few lines of code.
And when you go to that address.
Working with Databases
Node is designed work with many databases, both relational and NoSQL but NoSQL databases are best suited with Node. That being said, let’s look at some databases that can be used with node.
You should know what type of data you’re gonna store and what kind of queries you’ll need in order to choose the best database for you. If your use case isn’t really specific, it might be wise to use a database you’re familiar with. On the other hand, this can be a nice opportunity and environment to try and learn new databases.
How to start using a database in Node
First, you need to install drivers for the database you’re gonna use. You install them with NPM as usual:
After that you need to create a connection with the database and you’re all set. There are a lot of packages that can help you work with database, like Express and Mongoose.
There’s a lot more to say, but this article is meant to be just an introduction to NodeJS, so we won’t get into much detail here.
NodeJS has much to offer and we hope that this introduction was helpful. NodeJS is mostly used for web app development. Besides that, Node can be used in ChatBot development, server-side scripting, front-end and much more. We will explore some of these in some other article.