Thursday, August 26, 2021

Express



In this tutorial, we will also have a look at the express framework. This framework is built in such a way that it acts as a minimal and flexible Node.js web application framework, providing a robust set of features for building single and multipage, and hybrid web application.
What is Express.js?

Express.js is a Node js web application server framework, which is specifically designed for building single-page, multi-page, and hybrid web applications.

It has become the standard server framework for node.js. Express is the backend part of something known as the MEAN stack.

The MEAN is a free and open-source JavaScript software stack for building dynamic web sites and web applications which has the following components;

1) MongoDB - The standard NoSQL database

2) Express.js - The default web applications framework

3) Angular.js - The JavaScript MVC framework used for web applications

4) Node.js - Framework used for scalable server-side and networking applications.

The Express.js framework makes it very easy to develop an application which can be used to handle multiple types of requests like the GET, PUT, and POST and DELETE requests. Installing and using ExpressExpress gets installed via the Node Package manager. This can be done by executing the following line in the command line


npm install express

The above command requests the Node package manager to download the required express modules and install them accordingly.
  • npm install express --save
Let's use the newly installed Express framework and create a simple "Hello World" application.

create a simple server module which will listen on port no 3000. In this example, if a request is made through the browser on this port no, then server application will send a 'Hello' World' response to the client.

Node.js Express FrameWork Tutorial - Learn in 10 Minutes
var express=require('express');
var app=express();
app.get('/',function(req,res)
{
res.send('Hello World!');
});
var server=app.listen(3000,function() {}); 


Code Explanation:
In our first line of code, we are using the require function to include the "express module."

Before we can start using the express module, we need to make an object of the express module.

Here we are creating a callback function. This function will be called whenever anybody browses to the root of our web application which is http://localhost:3000. The callback function will be used to send the string 'Hello World' to the web page.
In the callback function, we are sending the string "Hello World" back to the client. The 'res' parameter is used to send content back to the web page. This 'res' parameter is something that is provided by the 'request' module to enable one to send content back to the web page.

We are then using the listen to function to make our server application listen to client requests on port no 8000. You can specify any available port over here.

Output:
Node.js Express FrameWork Tutorial - Learn in 10 Minutes


modules which installed with express

  • npm install body-parser -save
  • npm install cookie-parser -save
  • npm install multer --save


Saas

Software AS A Service(SAAS)

Software as a service (SaaS) is a model for the distribution of software where customers access software over the Internet. In SaaS, a service provider hosts the application at its data center and a customer accesses it via a standard web browser.

There are a few major characteristics that apply to most SaaS vendors:
Updates are applied automatically without customer intervention
The service is purchased on a subscription basis
No hardware is required to be installed by the customer

Why we use Saas?

SaaS offers significant benefits for organizations. Firstly, organizations don’t need an initial investment for hardware, as the processing power is supplied by the cloud provider. Likewise, there are no initial setup costs. The scalability features allow you to scale up resources on demand. You can provide privilege-based access by customizing settings. You don’t have to worry about updates or patches, and maintenance is handled by the cloud provider. As the applications are centrally hosted and remotely delivered to devices, you can access resources from any location and at any time. Most importantly, you can use any device to access resources.


Advantages of Sass:

  • It allows writing clean CSS in a programming construct.
  • It helps in writing CSS quickly.
  • It is a superset of CSS, which helps designers and developers work more efficiently and quickly.
  • As Sass is compatible with all versions of CSS, we can use any available CSS libraries.
  • It is possible to use nested syntax and useful functions such as color manipulation, mathematics and other values.



 

PHP

 PHP is a server scripting language and a powerful tool for making dynamic and interactive Web pages.

PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft's ASP.

PHP 7 is the latest stable release.



<!DOCTYPE html>
<html>
<body>

<?php
echo "My first PHP script!";
?>

</body>
</html>






What is PHP?

PHP is an acronym for "PHP: Hypertext Preprocessor"
PHP is a widely-used, open source scripting language
PHP scripts are executed on the server
PHP is free to download and use

What is a PHP File?

PHP files can contain text, HTML, CSS, JavaScript, and PHP code

PHP code is executed on the server, and the result is returned to the browser as plain HTML

PHP files have extension ".php


What Can PHP Do?

PHP can generate dynamic page content
PHP can create, open, read, write, delete, and close files on the server
PHP can collect form data
PHP can send and receive cookies
PHP can add, delete, modify data in your database
PHP can be used to control user-access
PHP can encrypt data

Why PHP?

  • PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
  • PHP is compatible with almost all servers used today (Apache, IIS, etc.)
  • PHP supports a wide range of databases
  • PHP is free. Download it from the official PHP resource: www.php.net
  • PHP is easy to learn and runs efficiently on the server-side



Thursday, August 22, 2019

ReactJs

React Js
React is a JavaScript library for building user interfaces. It is maintained by Facebook and a community of individual developers and companies. React can be used as a base in the development of single-page or mobile applications, as it is optimal for fetching rapidly changing data that needs to be recorded.

ReactJS basically is an open-source JavaScript library which is used for building user interfaces specifically for single-page applications. It's used for handling view layer for web and mobile apps. React also allows us to create reusable UI components.

Sunday, August 11, 2019

Ajax

HTML
Ajax is a set of web development techniques using many web technologies on the client-side to create asynchronous web applications. With Ajax, web applications can send and retrieve data from a server asynchronously without interfering with the display and behaviour of the existing page.

AJAX is a developer's dream, because you can:
  • Read data from a web server - after a web page has loaded
  • Update a web page without reloading the page
  • Send data to a web server - in the background
What is AJAX?

AJAX = Asynchronous JavaScript And XML.
AJAX is not a programming language.
AJAX just uses a combination of:
  • A browser built-in XMLHttpRequest object (to request data from a web server)
  • JavaScript and HTML DOM (to display or use the data)
AJAX is a misleading name. AJAX applications might use XML to transport data, but it is equally common to transport data as plain text or JSON text.

AJAX allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page.

AJAX

Heroku

Image result for heroku
What is Heroku used for?
Heroku is a container-based cloud Platform as a Service (PaaS). Developers use Heroku to deploy, manage, and scale modern apps. Our platform is elegant, flexible, and easy to use, offering developers the simplest path to getting their apps to market.

Why is Heroku free?
Heroku's free cloud services begin with the apps - apps which can be deployed to dynos - our lightweight Linux containers that are at the heart of the Heroku platform. When you sign up with Heroku, you automatically get a pool of free dyno hours to use for your apps. When your app runs, it consumes dyno hours.

 Heroku Buildpack
Buildpacks are composed of a set of scripts that will perform tasks such as retrieve dependencies or output generated assets or compiled code. If you are using a language that is officially supported by the Heroku platform, the build system will automatically detect which Heroku Buildpack is needed for the job.

The Heroku Platform
The Heroku network runs the customer's apps in virtual containers which execute on a reliable runtime environment, Heroku calls these containers Dynos. These Dynos can run code written in Node, Ruby, PHP, Go, Scala, Python, Java, Clojure. Heroku also provides custom buildpacks with which the developer can deploy apps in any other language. Heroku lets the developer scale the app instantly just by either increasing the number of dynos or by changing the type of dyno the app runs in.


How to install Heroku?
Run this from your terminal.
  1. sudo add-apt-repository "deb https://cli-assets.heroku.com/branches/stable/apt ./"
  2. curl -L https://cli-assets:heroku.com/apt/release.key | sudo apt-key add-
  3. sudo apt-get update
  4. sudo apt-get install heroku
Deploy your application to Heroku:
  • git init
  • git add .
  • git commit -m "first commit"
  • git status
  • heroku login(Enter your Heroku credentials)
  • heroku create ukifunwork2byname
  • git push heroku master(if it fails add heroku git remote:heroku git:remote -a yourapp & retry git push heroku master)
  • heroku open

Saturday, August 10, 2019

NODEJS MONGO-DB


We can create a mongo database through mongo coding. In spite of this, we can access MongoDB through Node.js. It is a server-side language used in JavaScript language.


To create a database in MongoDB, start by creating a MongoClient object, then specify a connection URL with the correct IP address and the name of the database you want to create.


Node.js can use this module to manipulate the MongoDB database:
var mongo = require('mongodb');

Creating a Database

To create a database in MongoDB, start by creating a MongoClient object, then specify a connection URL with the correct ip address and the name of the database you want to create


Creating a Collection

To create a collection in MongoDB, use the createCollection() method:


var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";

MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("mydb");
dbo.createCollection("customers", function(err, res) {
if (err) throw err;
console.log("Collection created!");
db.close();
});
});



Insert Into Collection

To insert a record, or document as it is called in MongoDB, into a collection, we use the insertOne() method.
The first parameter of the insertOne() method is an object containing the name(s) and value(s) of each field in the document you want to insert.

var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";

MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("mydb");
var myobj = { name: "Company Inc", address: "Highway 37" };
dbo.collection("customers").insertOne(myobj, function(err, res) {
if (err) throw err;
console.log("1 document inserted");
db.close();
});
});



Find OneTo select data from a collection in MongoDB, we can use the findOne() method.

The findOne() method returns the first occurrence in the selection.

The first parameter of the findOne() method is a query object. In this example, we use an empty query object, which selects all documents in a collection (but returns only the first document).


var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";

MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("mydb");
dbo.collection("customers").findOne({}, function(err, result) {
if (err) throw err;
console.log(result.name);
db.close();
});
});



Sort 

Use the sort() method to sort the result in ascending or descending order.

The sort() method takes one parameter, an object defining the sorting order.
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";

MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("mydb");
var mysort = { name: 1 };
dbo.collection("customers").find().sort(mysort).toArray(function(err, result) {
if (err) throw err;
console.log(result);
db.close();
});
});



Delete Document

To delete a record, or document as it is called in MongoDB, we use the deleteOne() method.

The first parameter of the deleteOne() method is a query object defining which document to delete.

var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";

MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("mydb");
var myquery = { address: 'Mountain 21' };
dbo.collection("customers").deleteOne(myquery, function(err, obj) {
if (err) throw err;
console.log("1 document deleted");
db.close();
});
});



Drop Collection

You can delete a table, or collection as it is called in MongoDB, by using the drop() method.

The drop() method takes a callback function containing the error object and the result parameter which returns true if the collection was dropped successfully, otherwise it returns false.

var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";

MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("mydb");
dbo.collection("customers").drop(function(err, delOK) {
if (err) throw err;
if (delOK) console.log("Collection deleted");
db.close();
});
});



Update Document


You can update a record, or document as it is called in MongoDB, by using the updateOne() method.

The first parameter of the updateOne() method is a query object defining which document to update.


var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://127.0.0.1:27017/";

MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("mydb");
var myquery = { address: "Valley 345" };
var newvalues = { $set: {name: "Mickey", address: "Canyon 123" } };
dbo.collection("customers").updateOne(myquery, newvalues, function(err, res) {
if (err) throw err;
console.log("1 document updated");
db.close();
});
});



Express

In this tutorial, we will also have a look at the express framework. This framework is built in such a way that it acts as a minimal an...