Node js Introduction:
Node.js is a server-side platform built on Google Chrome's JavaScript Engine.Node.js is an open source, cross-platform runtime environment for developing server-side and networking applications. Node.js applications are written in JavaScript, and can be run within the Node.js runtime on OS X, Microsoft Windows, and Linux. Node.js also provides a rich library of various JavaScript modules which simplifies the development of web applications using Node.js to a great extent.
Features of Node js:
- Node.js is really fast: Having been built on Google Chrome's V8 JavaScript engine, its library is extremely fast for code execution.
- Node Package Manager (NPM): Node Package Manager has more than 50,000 bundles, so whatever functionality is required for an application can be easily imported from NPM.
- Node.js uses asynchronous programming: All APIs of Node.js library are asynchronous (i.e., non-blocking), so a Node.js-based server does not wait for the API to return data. The server calls the API, and in the event that no data is returned, the server moves to the next API the Events module of Node.js helps the server get a response from the previous API call. This also helps with the speed of Node.js.
- No buffering: Node.js dramatically reduces the processing time while uploading audio and video files. Node.js applications never buffer data and simply output the data in chunks.
- Single-threaded: Node.js makes use of a single-threaded model with event looping. As a result, it can provide service to a much larger number of requests than traditional servers like Apache HTTP Server.
- Highly scalable: Node.js server responds in a non-blocking way, making it highly scalable in contrast with traditional servers, which create limited threads to handle requests.
Important parts of Node js:
- Modules: Modules are like JavaScript libraries that can be used in a Node.js application to include a set of functions. In order to include a module in a Node.js application, use the require( ) function with the parenthesis containing the name of the module. for eg(http, fs).
- Console: The console is a module that provides a method for debugging that is similar to the basic JavaScript console provided by internet browsers. It prints messages to stdout and stderr.
- Cluster: Node.js is built-on on the concept of single-threaded programming. Cluster is a module that allows multi-threading by creating child processes that share the same server port and run simultaneously.
- Global: Global objects in Node.js are available in all modules. These objects are functions, modules, strings, etc
- Error Handling: Node.js applications experience four types of errors. Errors in Node.js are handled through exceptions.
- Standard Javascript errors: syntax errors, type error etc.
- System errors: File does not exist
- User specific errors: Errors specified by user in the console
- Asseration errors: Special type of error that occurs in case of logic violation
- Streaming: Streams are the objects that let you read data or write data continuously. There are four types of streams:
- Readable: These are the types of streams from which data can be read
- Writable: These are the types of streams to which data can be written
- Duplex: These are both readable and writable streams
- Transform: Streams that can manipulate the data while it is being read or written
- Buffer: Buffer is a module that allows the handling of streams that contain only binary data.
- Domain: The domain module intercepts errors that remain unhandled. Two methods are used for intercepting these errors:
- Internal Binding: Error emitter executes its code inside the run method
- External Binding: Error emitter is explicitly added to a domain via its add method
- DNS: DNS module is used to connect to a DNS server. DNS module is also used for performing name resolution without a network communication
- Debugger: Node.js includes a debugging utility that can be accessed by a built-in debugging client. Node.js debugger is not feature-packed but supports the simple inspection of code. The debugger can be used in the terminal by using the 'inspect' keyword before the name of the JavaScript file.
What is an API?(https://www.mulesoft.com/resources/api/what-is-an-api)
An application programming interface, or API, enables companies to open up their applications’ data and functionality to external third-party developers, business partners, and internal departments within their companies. This allows services and products to communicate with each other and leverage each other’s data and functionality through a documented interface. Developers don't need to know how an API is implemented; they simply use the interface to communicate with other products and services. API use has surged over the past decade, to the degree that many of the most popular web applications today would not be possible without APIs.
- youtube link: https://www.youtube.com/watch?v=s7wmiS2mSXY
Node js Basics: ( https://www.w3schools.com/nodejs/)
- Modules
- File system
- NPM
- MYSQL
- MongoDB
What is REST API ? (https://www.sitepoint.com/developers-rest-api/)
An API, or application programming interface, is a set of rules that define how applications or devices can connect to and communicate with each other. A REST API is an API that conforms to the design principles of the REST, or representational state transfer architectural style.
- youtube link for creating REST API using express framework: https://www.youtube.com/watch?v=2ojkb44XObc
Nodejs and MYSQL connection: ( https://www.youtube.com/watch?v=hGZX_SA7lYg)(https://www.w3schools.com/nodejs/nodejs_mysql.asp)
Nodejs and redis: (https://www.codementor.io/@brainyfarm/caching-with-redis-node-js-example-h6o9ii72i)(https://www.npmjs.com/package/ioredis)
Redis simplifies your code by enabling you to write fewer lines of code to store, access, and use data in your applications. For example, if your application has data stored in a hashmap, and you want to store that data in a data store – you can simply use the Redis hash data structure to store the data.
Nodejs and mongodb: (https://www.w3schools.com/nodejs/nodejs_mongodb_create_db.asp)
Nodejs and Moongoose: (https://www.npmjs.com/package/mongoose)
Noddjs and sequelize: (https://www.npmjs.com/package/sequelize)
- Sequelize connection: https://www.geeksforgeeks.org/how-to-use-sequelize-in-node-js/#:~:text=Sequelize%20is%20a%20promise%2Dbased,read%20replication%20and%20many%20more.
- Data Types in sequelize: https://sequelize.org/v5/manual/data-types.html#:~:text=BLOB%20%2F%2F%20BLOB%20(bytea%20for,MySQL%20(use%20defaultValue%3A%20Sequelize.
- Models Basic: https://sequelize.org/master/manual/model-basics.html Models are the essence of Sequelize. A model is an abstraction that represents a table in your database. In Sequelize, it is a class that extends Model. The model tells Sequelize several things about the entity it represents, such as the name of the table in the database and which columns it has (and their data types). A model in Sequelize has a name. This name does not have to be the same name of the table it represents in the database. Usually, models have singular names (such as User) while tables have pluralized names (such as Users)
- Model querying: https://sequelize.org/master/manual/model-querying-basics.html
Nodejs callback: (https://www.tutorialspoint.com/nodejs/nodejs_callbacks_concept.htm)
Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given task. Node makes heavy use of callbacks. All the APIs of Node are written in such a way that they support callbacks.
Important nodejs libraries:
- lodash: (https://zetcode.com/javascript/lodash/)(https://lodash.com/docs/4.17.15) Lodash is a JavaScript library that provides utility functions for common programming tasks using a functional programming paradigm; it builds upon the older underscore.js library.Lodash has several built-in utility functions that make coding in JavaScript easier and cleaner. Instead of writing common functions, again and again, the task can be accomplished with a single line of code.
- momentjs: (https://momentjs.com/) - A JavaScript date library for parsing, validating, manipulating, and formatting dates.
- MD5 - (https://www.npmjs.com/package/md5)
- SHA512 - (https://www.npmjs.com/package/js-sha512)
- fs: (https://www.w3schools.com/nodejs/nodejs_filesystem.asp)The fs module provides a lot of very useful functionality to access and interact with the file system.
- Axios: ( https://zetcode.com/javascript/axios/)(https://www.npmjs.com/package/axios)Axios is a Javascript library used to make HTTP requests from node.js or XMLHttpRequests from the browser and it supports the Promise API that is native to JS ES6. It can be used intercept HTTP requests and responses and enables client-side protection against XSRF. It also has the ability to cancel requests. It is used to call remote url.
- validatorjs: (https://www.npmjs.com/package/validatorjs)The validatorjs library makes data validation in JavaScript very easy in both the browser and Node.js.
- pm2: (https://www.npmjs.com/package/pm2) PM2 is a production process manager for Node.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks.
- nodemailer - (https://www.w3schools.com/nodejs/nodejs_email.asp) - Send e-mails from Node.js
- bunyan logger - (https://www.npmjs.com/package/bunyan) - Bunyan is a simple and fast JSON logging library for node.js services
Async nodejs programming:(https://blog.logrocket.com/parallelism-concurrency-and-async-programming-in-node-js/)
Node.js uses an asynchronous event-driven design pattern, which means that multiple actions are taken at the same time while executing a program. For example, if there are two endpoints that follow one another in the program, the server will move one to make a request to the second endpoint without waiting for the first to return data.
restify framework: (http://restify.com/docs/server-api/)
restify is a node.js module built specifically to enable you to build correct REST web services. It intentionally borrows heavily from express as that is more or less the de facto API for writing web applications on top of node.js.
Restify-Errors(https://github.com/restify/errors)
npm trends: ( https://www.npmtrends.com/)
Comparing similar libraries of nodejs.
Basic Understanding of github:(https://www.youtube.com/watch?v=77W2JSL7-r8)
github commands: https://youtu.be/eL_0Ok_Gkas
API testing tools:
- postman: https://www.youtube.com/watch?v=t5n07Ybz7yI&t=2s
- insomania: https://www.youtube.com/watch?v=H16GUC9Svyk