Friday 29 December 2017

Node JS - EJS Effective JavaScript templating <% = EJS %>


what is EJS 
EJS Effective JavaScript template
E" is for "effective." EJS is a simple templating language that lets you generate HTML markup with plain JavaScript.
 No religiousness about how to organize things. No reinvention of iteration and control-flow. It's just plain JavaScript.

Features
=========
Fast compilation and rendering
Simple template tags: <% %>
Custom delimiters (e.g., use <? ?> instead of <% %>)
Includes
Both server JS and browser support
Static caching of intermediate JavaScript
Static caching of templates
Complies with the Express view system

Installation:
============
It's easy to install EJS with NPM.
$ npm install ejs

e.g:
=====
var ejs = require('ejs'),
    people = ['geddy', 'neil', 'alex'],
    html = ejs.render('<%= people.join(", "); %>', {people: people});

Tags:
====
<% 'Scriptlet' tag, for control-flow, no output
<%= Outputs the value into the template (HTML escaped)
<%- Outputs the unescaped value into the template
<%# Comment tag, no execution, no output
<%% Outputs a literal '<%'
%> Plain ending tag
-%> Trim-mode ('newline slurp') tag, trims following newline

custom Delimeters:
------------------
Custom delimiters can be applied on a per-template basis, or globally:

var ejs = require('ejs'),
    users = ['geddy', 'neil', 'alex'];

// Just one template
ejs.render('<?= users.join(" | "); ?>', {users: users},
    {delimiter: '?'});
// => 'geddy | neil | alex'

// Or globally
ejs.delimiter = '$';
ejs.render('<$= users.join(" | "); $>', {users: users});

Ref: http://ejs.co/

Thursday 28 December 2017

NodeJs - Nodemon - reload , automatically


Nodemon is a utility that will monitor for any changes in your source and automatically restart your server. Perfect for development. Install it using npm.


Just use nodemon instead of node to run your code, and now your process will automatically restart when your code changes. To install, get node.js, then from your terminal run:



npm install -g nodemon

Features:
-----------

Automatic restarting of application.

Detects default file extension to monitor.
Default support for node & coffeescript, but easy to run any executable (such as python, make, etc).
Ignoring specific files or directories.
Watch specific directories.
Works with server applications or one time run utilities and REPLs.
Requirable in node apps.
Open source and available on github.

REf: https://nodemon.io/