Sunday, 20 January 2019

node.js


What is Node.js?

  • Node.js is an open source server framework
  • Node.js is free
  • Node.js runs on various platforms (Windows,
  • Linux, Unix, Mac OS X, etc.)
  • Node.js uses JavaScript on the server


Why Want to use Node.js?


  • A common task for a web server can be to open a file on the server and return the content to the client.
  • Here is how PHP or ASP handles a file request:
  • Sends the task to the computer's file system.
  • Waits while the file system opens and reads the file.
  • Returns the content to the client.
  • Ready to handle the next request.

Here is how Node.js handles a file request:


  • Sends the task to the computer's file system.
  • Ready to handle the next request.
  • When the file system has opened and read the file, the server returns the content to the client.
  • Node.js eliminates the waiting, and simply continues with the next request.
  • Node.js runs single-threaded, non-blocking, asynchronously programming, which is very memory efficient.


What Can Node.js Do?

  • Node.js can generate dynamic page content
  • Node.js can create, open, read, write, delete, and close files on the server
  • Node.js can collect form data
  • Node.js can add, delete, modify data in your database


What is a Node.js File?


  • Node.js files contain tasks that will be executed on certain events
  • A typical event is someone trying to access a port on the server
  • Node.js files must be initiated on the server before having any effect
  • Node.js files have extension ".js

Install Node.js via NVM


Step -1
  • sudo apt-get update
Step -2
  • sudo apt-get install build-essential libssl-dev

Step -3
  • sudo curl https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

If no curl
sudo apt-get install curl
https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash


Step -4
source ~/.profile


Step -5
nvm --version


Step-6
nvm install 6.16.0


Step -7
nvm ls


Step-8
node --version


Step -9
npm --version

What Concepts are in Node.js?


* The following diagram depicts some important parts of Node.js which we will discuss in detail in the subsequent chapters.



5.Where to Use Node.js?
  Following are the areas where Node.js is proving itself as a perfect technology    partner.

I/O bound Applications
Data Streaming Applications
Data Intensive Real-time Applications (DIRT)
JSON APIs based Applications
Single Page Applications

--Node.js  modules--


 1.What is a Module in Node.js?

   * Consider modules to be the same as JavaScript libraries. 
     * A set of functions you want to include in your application.

--Include Modules--

* To include a module, use the require() function with the name of the module:
1.var http = require('http'); 
* Now your application has access to the HTTP module, and is able to create a server:
http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type''text/html'});
    res.end('Hello World!');
}).listen(8080); 

 

--Create Your Own Modules--

* You can create your own modules, and easily include them in your applications.
* The following example creates a module that returns a date and time object:

exports.myDateTime = function () {
    return Date();
};  

Use the exports keyword to make properties and methods available outside the module file.
Save the code above in a file called "mycreatemodule.js"


var http = require('http');
var dt = require('./mycraetemodule');

             ** Include Your Own Module **

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type''text/html'});
    res.write("The date and time are currently: " + dt.myDateTime());
    res.end();
}).listen(8080);
 

better way to build a startup


better way to get a startup!!!


before your startup you want to ask some questions with your idea and then if the question's answer is worth you can start your startup as well as

answering the following questions....


1. Your idea 

2. What problems do you want to solve? 
3. What is your target market? 
4. Who are your customers? 
5. How does it solve the problems? 
6. What features will your product have?


Sunday, 13 January 2019

MongoDB

mongodb


MongoDB is an open-source document database and leading NoSQL database.
It is written in C++.
It is a cross-platform.
Document oriented data based.
that provides, high performance, high availability, and easy scalability.It works on concept of collection
and document.

Basic syntax of use DATABASE statement is as follows −
.use DATABASE_NAME 
use music


Your created database (mydb) is not present in list.
To display database, you need to insert at least one document into it.
db.movie.insert({"name":" songdetails"})


MongoDB db.dropDatabase() command is used to drop a existing database.

db.dropDatabase()

To check the list of available databases by using the command, show dbs.

>show dbs
local      0.78125GB
mydb       0.23012GB
test       0.23012GB


MongoDB db.createCollection(name, options) is used to create collection.

db.createCollection(name, options)

MongoDB's db.collection.drop() is used to drop a collection from the database.

db.COLLECTION_NAME.update(SELECTION_CRITERIA, UPDATED_DATA)

Example:


1) Create a Database called music​.


  • use music

2) Create a collection called songdetails​.


  • db.createCollection("songdetails")


3) Create the above 5 song documents.


db.songdetails.insert({"Song Name":"Thaniye Thananthaniye","Film":"Rhythm","Music Director":"A.R.Rahman","Singer":"Shankar mahadevan"})
WriteResult({ "nInserted" : 1 })
db.songdetails.insert({"Song Name":"Evano Oruvan","Film":"Alai Payuthey","Music Director":"A.R.Rahman","Singer":"Swarnalatha"})
WriteResult({ "nInserted" : 1 })
db.songdetails.insert({"Song Name":"Roja Poonthottam","Film":"Kannukkul Nilavu","Music Director":"Ilaiyaraja","Singer":"Unnikirishnan,Anuradha Sriram"})
WriteResult({ "nInserted" : 1 })
db.songdetails.insert({"Song Name":"Vennilave Vennilave vinnaithandi","Film":"Minsara Kanavu","Music Director":"A.R.Rahman","Singer":"Hariharan,Sadhana Sargam"})
WriteResult({ "nInserted" : 1 })
db.songdetails.insert({"Song Name":"Sollamal Thottu Chellum Thendral","Film":"Dheena","Music Director":"Yuvan Shankar Raja","Singer":"Hariharan"})













4) List all documents created.
  • db.songdetails.find().pretty()



5) List A.R.Rahman’s songs.


  • db.songdetails.find({"Music Director":"A.R.Rahman"})



6) List A.R.Rahman’s songs sung by Unnikrishnan.


  • db.songdetails.find({"Music Director":"Ilaiyaraja","Singer":"Unnikirishnan,Anuradha Sriram"},{"Song Name":1,_id:0})

7) Delete the song which you don’t like.
  • db.songdetails.remove({"Song Name":"Evano Oruvan"})



8) Add new song which is your favourite.
  • db.songdetails.insert({"Song Name":"Kannana Kanne","Film":"Viswasam","Music Director":"D.imman","Singer":"Sid Sriram"})

9) List Songs sung by Sid sriram from Viswasam film.


  • db.songdetails.find({"Film":"Viswasam","Singer":"Sid Sriram"},{"Song Name":1,_id:0})



10)List out the singers’ names in your document.


  • db.songdetails.find({},{"Singer":1,_id:0}).pretty()





example2




1) Create a Database called student
use student


2) Create a collection called ​studentmarks
db.creatCollection(“studentmarks”)

3) Create the documents listed in above table.

db.songdetails.insert({"name":"Malal","maths_marks":45,"english_marks":53,"science_marks":72})
.
.
.

4) Increase the maths marks of Mala by 6 marks







5) List the names of students who got more than 50 marks in Maths Subject.


6)Add a new column(field) for Average for all students.
db.studentmarks.aggregate({$addFields:{“avarage”:””}}).pretty()              

7) Update Marks_Science=75 to Lucky .
db.studentmarks.update({“name”:”Lucky”},{$set:{science_marks”:75}})





8) List the names who got more than 50 marks in all subjects.

db.studentmarks.find({$and:[{"english_marks":{$gt:50}},{"science_marks":{$gt:50}},{"maths_marks":{$gt:50}}]},{"name":1,_id:0})



9) List the names who got less than 50 marks in Maths subject and more than 50 marks in English
db.studentmarks.find({$and:[{"english_marks":{$gt:50}},{"maths_marks":{$lt:50}}]},{"name":1,_id:0})



10) List the names who got less than 40 in both Maths and Science.

db.studentmarks.find({$and:[{"science_marks":{$lt:40}},{"maths_marks":{$lt:40}}]},{"name":1,_id:0})
11) Remove Science column/field for Raam
db.studentmarks.update({"name":"Raam"},{$unset:{"science_marks":88}})


12) Update John’s Math mark as 87 and English mark as 23, if john not available upsert.

db.studentmarks.insert({"name":"John","maths_marks":87,"english_marks":23})

13) Rename the english_marks column/field for John to science_marks

db.studentmarks.update({"name":"John"},{$rename:{"english_marks":"science_marks"}})




14) Remove Kumaran’s document from collection

db.studentmarks.remove({"name":"Kumaran"})


15) Find Kala’s or Aruli’s math_marks and science_marks

db.studentmarks.find({"name":"Aruli"},{"maths_marks":1,"science_marks":1}).pretty()

Tuesday, 8 January 2019

SASS

Sass

Image result for sass




Features of Sass

  • It is more stable, powerful, and compatible with versions of CSS.
  • It is a super set of CSS and is based on JavaScript.
  • It is known as syntactic sugar for CSS, which means it makes easier way for user to read or express the things more clearly.
  • It uses its own syntax and compiles to readable CSS.
  • You can easily write CSS in less code within less time.
  • It is an open source pre-processor, which is interpreted into CSS.

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.

Converting Syntax:

# Convert Sass to SCSS
$ sass-convert style.sass style.scss

# Convert SCSS to Sass
$ sass-convert style.scss style.sass

Store data in Sass

One feature of Sass that's different than CSS is it uses variables. They are declared and set to store data, similar to JavaScript.
In JavaScript, variables are defined using the letand constkeywords. In Sass, variables start with a $followed by the variable name.
Example:
$main-fonts: Arial, sans-serif; $headings-color: green; //To use variables: h1 {   font-family: $main-fonts;   color: $headings-color; }

Nest CSS with Sass

Sass allows nesting of CSS rules, which is a useful way of organizing a style sheet.
nav {
  background-color: red; } nav ul {   list-style: none; } nav ul li {   display: inline-block; }

Thursday, 27 December 2018