Skip to main content

Posts

Showing posts from April 6, 2022

Node.js MongoDB Tutorial with Examples

Node.js MongoDB Tutorial Mostly all modern-day web applications have some sort of data storage system at the backend. For example, if you take the case of a web shopping application, data such as the price of an item would be stored in the database. The Node js framework can work with databases with both relational (such as Oracle and MS SQL Server) and non-relational databases (such as MongoDB). In this tutorial, we will see how we can use databases from within Node js applications. In this tutorial, you will learn- Node.js and NoSQL Databases Using MongoDB and Node.js How to build a node express app with MongoDB to store and serve content Node.js and NoSQL Databases Over the years, NoSQL database such as  MongoDB  and MySQL have become quite popular as databases for storing data. The ability of these databases to store any type of content and particularly in any type of format is what makes these databases so famous. Node.js has the ability to work with both MySQL and MongoD...
In previous tutorials, you would have seen callback functions which are used for Asynchronous events. But sometimes callback functions can become a nightmare when they start becoming nested, and the program starts to become long and complex. In this tutorial, you will learn- What are promises? Callbacks to promises Dealing with nested promises Creating a custom promise What are promises? Before we start with promises, let’s first revisit what are “callback” functions in Node.js. We have seen these callback functions a lot in the previous chapters, so let’s quickly go through one of them. The example below shows a code snippet, which is used to connect to a  MongoDB  database and perform an update operation on one of the records in the database. In the above code, the part of the function(err,db) is known as the declaration of an anonymous or callback function. When the MongoClient creates a connection to the MongoDB database, it will return to the callback function once the co...

node js questions and answers

1) What is node.js? Node.js is a Server side scripting which is used to build scalable programs. Its multiple advantages over other server side languages, the prominent being non-blocking I/O. 2) How node.js works? Node.js works on a v8 environment, it is a virtual machine that utilizes JavaScript as its scripting language and achieves high output via non-blocking I/O and single threaded event loop. 3) What do you mean by the term I/O? I/O is the shorthand for input and output, and it will access anything outside of your application. It will be loaded into the machine memory to run the program, once the application is started. 4) What does event-driven programming mean? In computer programming, event driven programming is a programming paradigm in which the flow of the program is determined by events like messages from other programs or threads. It is an application architecture technique divided into two sections 1) Event Selection 2) Event Handling. 5) Where can we use node.js? Node....

Node.js Vs Python: What’s the Difference?

What is Node.js? Node.js  is a server-side platform built on Google Chrome’s JavaScript Engine. It uses a non-blocking, event-driven I/O model. It allows developers to create data-intensive real-time applications that run across distributed devices. Its applications are written in JavaScript. It can be run on OS X, Microsoft Windows, and Linux operating systems. It is widely used to run real-time server applications. What is Python? Python  is an object-oriented, high level, dynamic and multipurpose programming language. Python’s syntax and dynamic typing with interpreted nature, make it an ideal language for scripting. It supports multiple programming patterns, including object-oriented programming, functional programming, or procedural styles. Moreover, it an interpreted language which means it cannot convert to computer-readable code before its runs at runtime. In this comparison between Python vs NodeJS, we will cover: Features of Node js Features of Python Node JS Vs. Pyt...

Node.js Generators & Compare with Callbacks

n this tutorial, we are going to learn about Generators and their differences with Callbacks What are generators? Generators have become quite famous in  Node.js  in recent times and that is probably because of what they are capable of doing. Generators are function executions that can be suspended and resumed at a later point. Generators are useful when carrying out concepts such as ‘lazy execution’. This basically means that by suspending execution and resuming at will, we are able to pull values only when we need to. Generators have the below 2 key methods. Yield method  – The yield method is called in a function to halt the execution of the function at the specific line where the yield method is called. Next method  – This method is called from the main application to resume the execution of a function which has a yield method. The execution of the function will continue till the next yield method or till the end of the method. Let’s look at an example of how gen...

Bluebird Promises Tutorial | Bluebird JS with NPM Example

What is Bluebird JS? Bluebird JS is a fully-featured Promise library for JavaScript. The strongest feature of Bluebird is that it allows you to “promisify” other Node modules in order to use them asynchronously. Promisify is a concept applied to callback functions. This concept is used to ensure that every callback function which is called returns some value. So if a  NodeJS  module contains a callback function which does not return a value, and if we Promisify the node module, all the function’s in that specific node module would automatically be modified to ensure that it returns a value. So you can use BlueBird to make the  MongoDB  module run asynchronously. This just adds another level of ease when writing Node.js applications. We will look at an example of how to use the bluebird module. Our example will first establish a connection to the “Employee collection” in the “EmployeeDB” database. If “then” connection is established, then it will get all of the record...

Node.js Express FrameWork Tutorial – Learn in 10 Minutes

In this tutorial, we will study the Express framework. This framework is built in such a way that it acts as a minimal and flexible Node.js web application framework, providing a robust set of features for building single and multipage, and hybrid web application. In this tutorial, you will learn- What is Express.js? Installing and using Express What are Routes? Sample Web server using express.js What is Express.js? Express.js is a Node js web application server framework, which is specifically designed for building single-page, multi-page, and hybrid web applications. It has become the standard server framework for node.js. Express is the backend part of something known as the MEAN stack. The MEAN is a free and open-source  JavaScript  software stack for building dynamic web sites and web applications which has the following components; 1) MongoDB  – The standard NoSQL database 2) Express.js  – The default web applications framework 3) Angular.js  – The JavaScr...