Sunday, July 16, 2017

AJAX

AJAX

AJAX = Asynchronous JavaScript And XML.
AJAX is not a programming language.

How AJAX Works

Create an XMLHttpRequest Object

var xhttp = new XMLHttpRequest();  

Send a Request To a Server

xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();



GET Requests

xhttp.open("GET", "demo_get.asp", true);
xhttp.send(); 



POST Requests

xhttp.open("POST", "demo_post.asp", true);
xhttp.send(); 


more information visit https://www.w3schools.com/xml/ajax_intro.asp


 


 

ReactJS

ReactJS

React is front end library developed by Facebook. It's used for handling view layer for the web and mobile apps. 

React Features

1)JSX
2)Components
3)Unidirectional data flow and Flux
4)License   


Then this install

Install Global Packages

npm install -g babel

npm install -g babel-cli


Create Root Folder


npm install webpack --save

npm install webpack-dev-server --save
npm install react --save

npm install react-dom --save
npm install babel-core

npm install babel-loader

npm install babel-preset-react

npm install babel-preset-es2015

Create files

touch index.html
touch App.jsx
touch main.js
touch webpack.config.js
 
More detail next blogg 
Thank you 
 

 



 


 



 

 

Mongoose

Mongoose
1) npm -v
2) mongo --version
 3)then create these folders

4) npm install --save-dev nodemon 5) npm install express --save
 6) 
Open the server.js file and type/copy the code below into it
var express = require('express'), app = express(), port = process.env.PORT || 3000; app.listen(port); console.log('todo list RESTful API server started on: ' + port);
 7)  npm run start
 8) 
npm install mongoose --save
 9) 
open the todoListModel.js file in your api/models folder and type the following code into the file and save.
'use strict'; var mongoose = require('mongoose'); var Schema = mongoose.Schema; var TaskSchema = new Schema({ name: { type: String, Required: 'Kindly enter the name of the task' }, Created_date: { type: Date, default: Date.now }, status: { type: [{ type: String, enum: ['pending', 'ongoing', 'completed'] }], default: ['pending'] } }); module.exports = mongoose.model('Tasks', TaskSchema);
10) Get Put Delete Update
'use strict'; var mongoose = require('mongoose'), Task = mongoose.model('Tasks'); exports.list_all_tasks = function(req, res) { Task.find({}, function(err, task) { if (err) res.send(err); res.json(task); }); }; exports.create_a_task = function(req, res) { var new_task = new Task(req.body); new_task.save(function(err, task) { if (err) res.send(err); res.json(task); }); }; exports.read_a_task = function(req, res) { Task.findById(req.params.taskId, function(err, task) { if (err) res.send(err); res.json(task); }); }; exports.update_a_task = function(req, res) { Task.findOneAndUpdate({_id: req.params.taskId}, req.body, {new: true}, function(err, task) { if (err) res.send(err); res.json(task); }); }; exports.delete_a_task = function(req, res) { Task.remove({ _id: req.params.taskId }, function(err, task) { if (err) res.send(err); res.json({ message: 'Task successfully deleted' }); }); };

ExpressJs

ExpressJs
ExpressJS is a web application framework
node --version
v5.0.0
➧ npm --version
3.5.2

How to use npm

Globally:
npm install -g <package-name>
Locally:
npm install <package-name>

after  npm init

Then install this
➦ npm install --save express
➦ npm install -g nodemon

then create index.js
then type the following in it.

var express = require('express');

var app = express();

app.get('/', function(req, res){

res.send("Hello world!");

});

app.listen(3000);

then go to your terminal and type the following.

nodemon index.js

This will start the server. To test this app, open your browser and go to

http://localhost:3000 and you can see Hello world