NODE JS

Date: 5th November, 2016

NodeJs has following internal functionalities
Area Details
Assert This module provides a simple set of assertion tests that can be used to test in variants
Buffer Instances of the Buffer class are similar to arrays of integers but correspond to fixed-sized, raw memory allocations outside the V8 heap. The size of the Buffer is established when it is created and cannot be resized
Child process This module provides the ability to spawn child
Cluster A single instance of Node.js runs in a single thread. To take advantage of multi-core systems the user will sometimes want to launch a cluster of Node.js processes to handle the load
Console This module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers
Crypto This module provides cryptographic functionality that includes a set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign and verify functions.
Debugger Node.js includes a full-featured out-of-process debugging utility accessible via a simple TCP-based protocol and built-in debugging client.
DNS The dns module contains functions belonging to two different categories: Functions that use the underlying operating system facilities to perform name resolution, and that do not necessarily perform any network communication
Events
File system File I/O is provided by simple wrappers around standard POSIX functions
Global Global objects like __dirname – refer https://nodejs.org/api/globals.html
http To use the HTTP server and client - refer https://www.lynda.com/Express-js-tutorials/Handling-HTTP-requests-Node-js/502310/519129-4.html
https HTTPS is the HTTP protocol over TLS/SSL. In Node.js this is implemented as a separate module.
Net The net module provides you with an asynchronous network wrapper. It contains functions for creating both servers and clients (called streams)
OS The os module provides a number of operating system-related utility methods.
Path The path module provides utilities for working with file and directory paths
Process https://nodejs.org/api/process.html
Query String This module provides utilities for parsing and formatting URL query strings
Readline This module provides an interface for reading data from a Readable stream
Repl This module provides a Read-Eval-Print-Loop (REPL) implementation that is available both as a standalone program or includable in other applications.
Stream 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
String Decoder This module provides an API for decoding Buffer objects into strings in a manner that preserves encoded multi-byte UTF-8 and UTF-16 characters
Timers The timer module exposes a global API for scheduling functions to be called at some future period of time. Because the timer functions are globals, there is no need to call require('timers') to use the API.
TLS The tls module provides an implementation of the Transport Layer Security (TLS) and Secure Socket Layer (SSL) protocols that is built on top of OpenSSL
TTY This module provides the tty.ReadStream and tty.WriteStream classes. In most cases, it will not be necessary or possible to use this module directly
UDP The dgram module provides an implementation of UDP Datagram sockets
URL The url module provides utilities for URL resolution and parsing
UTIL The util module is primarily designed to support the needs of Node.js' own internal APIs. However, many of the utilities are useful for application and module developers as well
V8 The v8 module exposes APIs that are specific to the version of V8 built into the Node.js binary
VM The vm module provides APIs for compiling and running code within V8 Virtual Machine contexts
ZLIB The zlib module provides compression functionality implemented using Gzip and Deflate/Inflate.

Express Js

ExpressJS is a very popular module that adds web server functionality to NodeJS. And it also makes it easier to build websites and applications. It creates a routing mechanism so that your applications can pass along different types of requests easily. It also makes it easier to create an API or an application programming interface that can help you deal with data using ACTB verbs like get, put, and delete. Express also allows you to plug in other modules into the middle of the framework to perform certain types of tasks. Now because of this, these tools are called middleware. And so, instead of dictating a specific templating engine that you should use with Express, it gives you access to your choice of engines like Jade, or EJS, while still providing other features like giving users easy access to public files. So, while Node gives you a fast, Javascript based server with an event driven, non-blocking model, ExpressJS provides a simple way to create websites and applications by providing common features, like routing, APIs and ACTB verbs. Express also lets you easily plug into other middleware, and that makes it a great building block for a customized framework. Why should you use Express with NodeJS? Now to make things faster, NodeJS is very small and it doesn't do a lot by itself. But it requires additional modules to make it really useful.Installation process

$ npm install express –save

Express provides no Mime Type clause, easy routing , access to lots of http verbs, can get values from environmental variables One of the core features of Express is called routing. Routing allows you to get information for different parts of your website to users. Express provides a piece of middleware that takes care static contents also, example access to public folders containing css or images

Express Generator
$ npm install –g express_generator
Express generator is another Javascript library, after install you can generate express project templates Once installed type $express –h for options
Node Js View Templates
EJS EJS – is embedded java script used for view template $ npm install ejs –save Why EJS? The beauty of EJS is that, you can create partial views using EJS. For example you can have a common header, footer, navigation for all pages and just change the internal content using EJS. Also you are able to pass data to views. If you are HTML purist, you'll love EJS because it allows you to code in HTML without conflicting with Angular Pros: • Operating on plain HTML, no significant white spaces. Basically writing JavaScript, few restrictions here • Could be used for things other than HTML, eg config files, JSON • Filters support • No learning curve Cons: • No async support • Very verbose, PHP-like syntax • Includes are loaded from local file system (not even sure how client side is handled in this case)
Jade (Pug) https://www.youtube.com/watch?v=l5AXcXAP4r8 Concept is almost same like EJS By default express comes with Jade. But developer likes EJS more than Jade Pros: • No closing tags • White space significant indentation • Extensive layout inheritance • Macros support • Plain old school includes • Built in support for Markdown, CoffeeScript and others • Available implementations in php, scala, ruby, python and java. Cons: • Not everyone likes significant white space • JavaScript inlining can get cumbersome for more than one line • Requires a small runtime to use precompiled templates on the client • Not suitable for non-HTML output • No streaming support • Somewhat high learning curve Pug - This project was formerly known as "Jade."
Handlebar • The Handlebars library is another template engine. It inherits from Mustache and, for the most part, is compatible with Mustache’s syntax • This is not used widely currently
Nunjucks This is inspired by python templating language. $ npm install nunjucks -–save Pros: • Async support • Extensive layout inheritance • Macros support • Plain old school includes • Filters support • White space control • Operating on plain HTML, no significant white space • Clean, concise variable and loop controls syntax • Could be used for things other than HTML, eg config files, JSON • Custom tags support Cons: • Have to close your own tags (right?) • No streaming support • Somewhat high learning curve
Dust Dust.js is a heavily influenced by Mustache template language $ npm install dust -–save Pros: • Async & streaming support • Operating on plain HTML, no significant white space • Clean, concise variable and loop controls syntax • Could be used for things other than HTML, eg config files, JSON • Doesn’t pretend to be logic-less • Filters support Cons: • Can’t automatically load partials • Default global namespace for partials will require workaround to avoid collisions • Have to close your own tags (right?) • Preloading and naming templates for rendering feels strange • Somewhat high learning curve, especially if you want to get into streaming
Mustache $ npm install mustache –-save Pros: • Based on the popular Mustache templating language • Operating on plain HTML, no significant white space • Clean, concise variable and loop controls syntax • Could be used for things other than HTML, eg config files, JSON • Small learning curve Cons: • Cumbersome partials system requires to register all partials • Default global namespace for partials will require workaround to avoid collisions • No built-in layout system • Have to close your own tags (right?) • No streaming support
Hogan • Hogan.js was developed against the mustache test suite, so everything that holds true for templates as specified here, is also the case for hogan.js. • Twitter is this template
Twig • Twig.js is a pure JavaScript implementation of the Twig PHP templating language • It is similar to Nunjucks
Underscore One of the preferred starter web page theme is the one called Underscores and there are two main reasons for that. The first is that Underscores was created by the people at wordpress.com on automatic, so it's the theme that's being used as the starting point when they build new themes for WordPress command also for wordpress.org and it's a theme that's a good idea to use if you ever want to publish your themes either in the wordpress.org theme directory or on wordpress.com. The other reason is that Underscores is the most up-to-date starter theme there is. It's always at the cutting edge of WordPress standards, of HTML 5 web standards, and of accessibility standards. So if you want a good start you always want to start with Underscores. Now Underscores itself lives on GitHub, but when you want your own version to work with for when you want to start a new theme you always want to start here at underscores.me. This website will go to GitHub and pull down the latest version of Underscores then change it to be name spaced with your theme name and then give it to you so you could work with it.

Node Js Utilities & Important Libraries

Nodemon - Nodemon, an npm package monitor changes in folder for files and re-run the server if there are any changes. Reload - Code change reload, an npm package, helps to refresh browser to reload changes Grunt - Grunt is used for background tasks running and scheduling. Command line task runner. Grunt is the most commonly used task runner in the WordPress community. And it has great support for Sass, autoprefixer, and many other tools that are useful for WordPress theme designers and developers. Grunt is a JavaScript task runner application that runs in your command line, automatically performing common or repetitive tasks on your behalf. Common uses for Grunt include de-linting or de-bugging, and minifying JavaScript files, generating things like translation files and what we're doing here, pre-processing Sass and auto prefixing CSS. Grunt-cli : Is a simple command line tool. Install grunt-cli just will put the grunt command in your system path, allowing it to be run from any directory. Installing grunt-cli does not install the Grunt task runner! The job of the Grunt CLI is simple: run the version of Grunt which has been installed next to a Gruntfile. This allows multiple versions of Grunt to be installed on the same machine simultaneously. We install grunt-cli globally and main grunt package locally
$ npm install –g grunt-cli
$ npm install grunt --save
RequireJs RequireJS is library to load modules Modular programming is used to break large applications into smaller blocks of manageable code. Module based coding eases the effort for maintenance and increases reusability. However, managing dependencies between modules is a major concern developers face throughout the application development process. RequireJS is one of the most popular frameworks around for managing dependencies between modules. This tutorial examines the need for modularized code, and shows how RequireJS can help. https://www.sitepoint.com/understanding-requirejs-for-effective-javascript-module-loading/ Bower The browser package manager. Bower offers a generic, unopinionated solution to the problem of front-end package management, while exposing the package dependency model via an API that can be consumed by a more opinionated build stack. It is sort of npm for web projects Npm uses package.json and bower uses bower.json. Bower commands are same like Npm commands. Bower is created solely for the front-end and is optimized with that in mind. The biggest difference is that npm does nested dependency tree (size heavy) while Bower requires a flat dependency tree (puts the burden of dependency resolution on the user). A nested dependency tree means that your dependencies can have its own dependencies which can have their own, and so on. This is really great on the server where you don't have to care much about space and latency. It lets you not have to care about dependency conflicts as all your dependencies use e.g. their own version of Underscore. This obviously doesn't work that well on the front-end. Imagine a site having to download three copies of jQuery. The reason many projects use both is that they use Bower for front-end packages and npm for developer tools like Yeoman, Grunt, Gulp, JSHint, CoffeeScript, etc Refer - http://bower.io/
$ npm install –g bower
NGINX NGINX is used for reverse proxy and load balancing setups for Node JS For REHL 7, perform following commands
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install nginx18
After that perform following steps to avoid a bug
sudo cat /var/log/audit/audit.log | grep nginx | grep denied | audit2allow -M mynginx
sudo semodule -i mynginx.pp
under /etc/nginx/conf.d
create a file – hostname.conf and add for SSL and reverse proxy setup for Ghost
server {
listen 443 ssl;
server_name hostname;
ssl_certificate /path/ssl_cert;
ssl_certificate_key /path/ssl.key;
location / {
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   Host      $http_host;
    proxy_pass         http://127.0.0.1:2368;
}
}
Note: if Node Js is running on port 2368 Now start service nginx restart

Yeoman (YO)  Yeoman is an open source client-side development stack, consisting of tools and frameworks intended to help developers build web applications. Yeoman runs as a command-line interface written for Node.js and which combines several functions into one place, such as generating a starter template, managing dependencies, running unit tests, providing a local development server, and optimizing production code for deployment. Using a "generator" concept inspired by Ruby on Rails,[2] Yeoman first creates a basic project structure with vendor libraries included. The most basic Yeoman generator supplies the HTML5 Boilerplate, Normalize.css, the jQuery JavaScript library, and Modernize as a basic template for developers. Refer - http://yeoman.io/ It is a scaffolding tool. It is required for Oracle JET.

generator-oraclejet This Yeoman generator for Oracle JET lets you quickly set up a project for use as a web application or hybrid mobile application for Android, iOS or Windows 10. This is an open source project maintained by Oracle Corp. Use Cookbook to learn Oracle Jet Containers

Sass Sass is a CSS extension language that allows us to write SCSS files with extended abilities like variables, mixing, and nesting, that are then pre-processed into regular CSS. Why Sass is used widely for WordPress projects, and not and less or some other CSS pre- or post- processor? Well, since were working with WordPress, it's a good idea to use the CSS pre-processor used by WordPress core, and that is Sass

MongoDB

MongoDB (from humongous) is a free and open-source cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with schemas. MongoDB is developed by MongoDB Inc. and is free and open-source, published under a combination of the GNU Affero General Public License and the Apache License. To connect MongoDb from Nodejs, we have to use mongodb driver.

npm install mongodb --save

Angular Js

AngularJS (commonly referred to as "Angular" or "Angular.js") is a complete JavaScript-based open-source front-end web application framework mainly maintained by Google and by a community of individuals and corporations to address many of the challenges encountered in developing single-page applications. The JavaScript components complement Apache Cordova, the framework used for developing cross-platform mobile apps. It aims to simplify both the development and the testing of such applications by providing a framework for client-side model–view–controller (MVC) and model–view–viewmodel (MVVM) architectures, along with components commonly used in rich Internet applications.The AngularJS framework works by first reading the HTML page, which has embedded into it additional custom tag attributes. Angular interprets those attributes as directives to bind input or output parts of the page to a model that is represented by standard JavaScript variables. The values of those JavaScript variables can be manually set within the code, or retrieved from static or dynamic JSON resources.

According to JavaScript analytics service Libscore, AngularJS is used on the websites of Wolfram Alpha, NBC, Walgreens, Intel, Sprint, ABC News, and approximately 12,000 other sites out of 1 million tested in October 2016.[3]

AngularJS is the frontend part of the MEAN stack, consisting of MongoDB database, Express.js web application server framework, Angular.js itself, and Node.js runtime environment.

KnockoutJS Like Angular, knockout is also Javascript based open library used for declarative bindings and dependency tracking and developing webapp AngularJS and KnockoutJS are JavaScript libraries that help create rich and responsive web UI interactions. KnockoutJS is a library that connects parts of the UI to a data model using declarative bindings. The same can be said about AngularJS, which is where the confusion comes from. The fundamental difference between the two solutions is that AngularJS manages the whole application and defines guidelines on how the application code should be structured, whereas with KnockoutJS the application structure is entirely up to you. OracleJet users KnockoutJs framework.