Sunday, 16 July 2017

27.06.2017.

Tuesday.



Express


⟹What is Express


ExpressJS is a web application framework that provides you with a simple API to build
websites, web apps and back ends. With ExpressJS, you need not worry about low level
protocols, processes, etc.


Express provides a minimal interface to build our applications. It provides us the tools that
are required to build our app. It is flexible as there are numerous modules available
on npm, which can be directly plugged into Express.




⟹Pug


Pug (earlier known as Jade) is a terse language for writing HTML templates. 


It -
Produces HTML


Supports dynamic code
Supports reusability

It is one of the most popular template language used with Express.





⟹MongoDB and Mongoose

MongoDB is an open-source, document database designed for ease of development and
scaling. This database is also used to store data.


Mongoose is a client API for node.js which makes it easy to access our database from our
Express application.





⟹Express install


    node --version

    npm --version


    npm install -g <package-name>


➞Step 1: Start your terminal/cmd, create a new folder named hello-world and cd (create
directory) into it:



➟step 2
npm init

➞step 3
npm install --save express


ls node_modules #(dir node_modules for windows)

npm install -g nodemon


This is all we need to start development using the Express framework. To make our
development process a lot easier, we will install a tool from npm, nodemon. This tool
restarts our server as soon as we make a change in any of our files, otherwise we need to
restart the server manually after each file modification.




We have set up the development, now it is time to start developing our first app using
Express. Create a new file called index.js and type the following in it.



var express = require('express');
var app = express();
app.get('/', function(req, res){
res.send("Hello world!");
});
app.listen(3000);







Save the file, go to your terminal and type the following.

nodemon index.js


This will start the server. To test this app,



⟹ExpressJS – Routing



app.method(path, handler)

This METHOD can be applied to any one of the HTTP verbs – get, set, put, delete. An
alternate method also exists, which executes independent of the request type.
Path is the route at which the request will run.





⟹ExpressJS – HTTP Methods


➞GET ⇒The GET method requests a representation of the specified resource. Requests
using GET should only retrieve data and should have no other effect.




➞POST ⇒The POST method requests that the server accept the data enclosed in the
request as a new object/entity of the resource identified by




➞PUT ⇒The PUT method requests that the server accept the data enclosed in the
request as a modification to existing object identified by the URI. If it does not
exist then the PUT method should create one.



➞DELETE ⇒The DELETE method requests that the server delete the specified resource.






⟹Important Features of Pug


Let us now explore a few important features of Pug.
Simple Tags
Tags are nested according to their indentation. Like in the above example, <title> was
indented within the <head> tag, so it was inside it. But the <body> tag was on the same
indentation, so it was a sibling of the <head> tag.
We don’t need to close tags, as soon as Pug encounters the next tag on same or outer
indentation level, it closes the tag for us.

To put text inside of a tag, we have 3 methods:



➞Speace seperated


h1 Welcome to pug


➞Piped text

div  

➞To insert multiline text,

You can use the pipe operater 

  
➞Block of text 

div


But that gets tedious if you have a lot of text.
You can use "." at the end of tag to denote block of text.
To put tags inside this block, simply enter tag in a new line and
indent it accordingly.



No comments:

Post a Comment

Machine Learning Annotation Introduction

Data annotation in Machine Learning is the process of annotating/ labeling data to categorize the dataset to identify by ML models. It can b...