Node.js

Topics related to Node.js:

Getting started with Node.js

Node.js is an event-based, non-blocking, asynchronous I/O framework that uses Google's V8 JavaScript engine. It is used for developing applications that make heavy use of the ability to run JavaScript both on the client, as well as on server side and therefore benefit from the re-usability of code and the lack of context switching. It is open-source and cross-platform. Node.js applications are written in pure JavaScript and can be run within Node.js environment on Windows, Linux etc…

npm

Web Apps With Express

Filesystem I/O

In Node.js, resource intensive operations such as I/O are performed asynchronously, but have a synchronous counterpart (e.g. there exists a fs.readFile and its counterpart is fs.readFileSync). Since Node is single-threaded, you should be careful when using synchronous operations, because they will block the entire process.

If a process is blocked by a synchronous operation, the entire execution cycle (including the event loop) is halted. That means other asynchronous code, including events and event handlers, will not run and your program will continue to wait until the single blocking operation has completed.

There are appropriate uses for both synchronous and asynchronous operations, but care must be taken that they are utilized properly.

Exporting and Consuming Modules

While everything in Node.js is generally done asynchronously, require() is not one of those things. Since modules in practice only need to be loaded once, it is a blocking operation and should be used properly.

Modules are cached after the first time they are loaded. Should you be editing a module in development, you will need to delete its entry in the module cache in order to use new changes. That being said, even if a module is cleared out of the module cache, the module itself is not garbage collected, so care should be taken for its use in production environments.

Exporting and Importing Module in node.js

Installing Node.js

MySQL integration

Readline

package.json

Event Emitters

When an event "fires" (which means the same as "publishing an event" or "emitting an event"), each listener will be called synchronously (source), along with any accompanying data that was passed in to emit(), no matter how many arguments you pass in:

myDog.on('bark', (howLoud, howLong, howIntense) => {
  // handle the event
})
myDog.emit('bark', 'loudly', '5 seconds long', 'fiercely')

The listeners will be called in the order they were registered:

myDog.on('urinate', () => console.log('My first thought was "Oh-no"'))
myDog.on('urinate', () => console.log('My second thought was "Not my lawn :)"'))
myDog.emit('urinate')
// The console.logs will happen in the right order because they were registered in that order.

But if you need a listener to fire first, before all of the other listeners that have already been added, you can use prependListener() like so:

myDog.prependListener('urinate', () => console.log('This happens before my first and second thoughts, even though it was registered after them'))

If you need to listen to an event, but you only want to hear about it once, you can use once instead of on, or prependOnceListener instead of prependListener. After the event is fired and the listener gets called, the listener will automatically be removed, and won't be called again the next time the event is fired.

Finally, if you want to remove all of the listeners and start over, feel free to do just that:

myDog.removeAllListeners()

Autoreload on changes

Environment

Callback to Promise

Executing files or commands with Child Processes

When dealing with child processes, all of the asynchronous methods will return an instance of ChildProcess, while all the synchronous versions will return the output of whatever was run. Like other synchronous operations in Node.js, if an error occurs, it will throw.

Cluster Module

Exception handling

Keep a node application constantly running

Uninstalling Node.js

nvm - Node Version Manager

http

Using Streams

Deploying Node.js applications in production

Securing Node.js applications

Mongoose Library

async.js

File upload

Socket.io communication

Mongodb integration

Handling POST request in Node.js

Node.js uses streams to handle incoming data.

Quoting from the docs,

A stream is an abstract interface for working with streaming data in Node.js. The stream module provides a base API that makes it easy to build objects that implement the stream interface.

To handle in request body of a POST request, use the request object, which is a readable stream. Data streams are emitted as data events on the request object.

  request.on('data', chunk => {
    buffer += chunk;
  });
  request.on('end', () => {
    // POST request body is now available as `buffer`
  });

Simply create an empty buffer string and append the buffer data as it received via data events.

NOTE

  1. Buffer data received on data events is of type Buffer
  2. Create new buffer string to collect buffered data from data events for every request i.e. create buffer string inside the request handler.

Simple REST based CRUD API

Template frameworks

Node.js Architecture & Inner Workings

Debugging Node.js application

Node server without framework

Though Node has many framework to help you getting your server up and running, mainly:

Express: The most used framework

Total: The ALL-IN-ONE UNITY framework, that have everything and do not depend on any other framework or module.

But, there is always no one size fits all, so developer may need to build his/her own server, without any other dependency.

If the app i accessed through external server, CORS could be an issue, a code to avoid it had been provided.

Node.JS with ES6

Interacting with Console

Cassandra Integration

Creating API's with Node.js

Graceful Shutdown

Using IISNode to host Node.js Web Apps in IIS

Virtual Directory / Nested Application with Views Pitfall

If you're going to be using Express to render views using a View Engine, you'll need to pass the virtualDirPath value in to your views

`res.render('index', { virtualDirPath: virtualDirPath });`

The reason for doing this is to make your hyperlinks to other views host by your app and static resource paths to know where the site is being hosted without needing to modify all views after deployment. This is one of the more annoying and tedious pitfalls of using Virtual Directories with IISNode.

Versions

All of the examples above work with

  • Express v4.x
  • IIS 7.x/8.x
  • Socket.io v1.3.x or greater

CLI

NodeJS Frameworks

grunt

Further reading:

The Installing grunt guide has detailed information about installing specific, production or in-development, versions of Grunt and grunt-cli.

The Configuring Tasks guide has an in-depth explanation on how to configure tasks, targets, options and files inside the Gruntfile, along with an explanation of templates, globbing patterns and importing external data.

The Creating Tasks guide lists the differences between the types of Grunt tasks and shows a number of sample tasks and configurations.

Using WebSocket's with Node.JS

metalsmith

Parsing command line arguments

Client-server communication

Node.js Design Fundamental

Connect to Mongodb

Performance challenges

Send Web Notification

Remote Debugging in Node.JS

Mysql Connection Pool

Database (MongoDB with Mongoose)

Good coding style

I would recommend to a beginner to start with this style of coding. And if anybody can suggest a better way(p.s i opted this technique and is working efficiently for me in an app used by more then 100k users), feel free for any suggestions. TIA.

Restful API Design: Best Practices

Deliver HTML or any other sort of file

TCP Sockets

Hack

Bluebird Promises

Async/Await

Koa Framework v2

Unit testing frameworks

ECMAScript 2015 (ES6) with Node.js

Routing ajax requests with Express.JS

Sending a file stream to client

NodeJS with Redis

Using Browserfiy to resolve 'required' error with browsers

Node.JS and MongoDB.

Passport integration

Password must always be hashed. A simple way to secure passwords using NodeJS would be to use bcrypt-nodejs module.

Dependency Injection

NodeJS Beginner Guide

Use Cases of Node.js

Sequelize.js

PostgreSQL integration

How modules are loaded

Node.js with Oracle

Synchronous vs Asynchronous programming in nodejs

Node.js Error Management

Node.js v6 New Features and Improvement

Eventloop

Nodejs History

passport.js

Asynchronous programming

Node.js code for STDIN and STDOUT without using any library

MongoDB Integration for Node.js/Express.js

Lodash

csv parser in node js

Loopback - REST Based connector

Running node.js as a service

Node.js with CORS

Getting started with Nodes profiling

The node-inspector fails to attach to the node bebug process sometimes in which case you will not be able to get the debug breakpoint in devtools .Try refreshing the devtools tab multiple times and wait for some seconds to see if it is in debug mode.

If not restart the node-inspector from command line.

Node.js Performance

Yarn Package Manager

OAuth 2.0

Node JS Localization

Deploying Node.js application without downtime.

Node.js (express.js) with angular.js Sample code

NodeJs Routing

At last, Using Express Router you can use routing facility in you application and it is easy to implement.

Creating a Node.js Library that Supports Both Promises and Error-First Callbacks

MSSQL Intergration

We have assumed that we will have a local instance of mssql database server running on local machine . You can refer this document to do the same .

Also make sure you appropriate user created with privileges added as well.

Project Structure

The project above uses browserify and vue.js modules as application base view and minification libs. So the project structure may changes minutely based on which mvc framework you use e.g. The build directory in public will need to contain all the mvc code. You can have a task which does this for you .

Avoid callback hell

Arduino communication with nodeJs

N-API

Multithreading

Understanding the Event Loop is important to understand how and why to use multiple threads.

Windows authentication under node.js

Require()

Using require() allows code to be structured in a way similar to Java's use of classes and public methods. If a function is .export'ed, it can be require'ed in another file to be used. If a file is not .export'ed, it cannot be used in another file.

Route-Controller-Service structure for ExpressJS

Push notifications