Categories
Backend Developer Database

Sql Vs NoSql – Which Is Best For You?

Structured Query language (SQL) 

SQL database is a domain-specific programming language used for managing, and designing data stored in a relational database management system (RDBMS). Also, it is used for stream processing in RDBMS. Relational databases use relations (typically called tables) to store data and match that particular data by using common characteristics within that dataset.

sql vs nosql

SQL often pronounced as “S-Q-L” or “See-Quel” is the standard language for dealing with Relational Databases invented in 1974 and is still going strong with their latest released version in 2016.  It is particularly useful in handling structured data which is data incorporating relations among entities and variables.

A relational database defines relationships in the form of tables and SQL is effectively used to insert, search, update, delete database records.

Database

SQL database is originally based on Relational Algebra and Tuple relational calculus consisting of various types of statements. These statements can also be classified as sublanguages, called: A Data query language (DQL),  Data Definition Language (DDL), a Data Control Language (DCL), and a Data Manipulation Language (DML).

Schema For SQL

Schema in SQL is a template/ a pattern that describes qualities regarding the information a database will store.

Specifically, it describes:

  • Type – Type of information refers to a specific piece of information and general attributes of that particular information. For example, integers can be positive or negative and they don’t have a fractional part. This piece of information about their characteristics makes a huge difference in the way they are being efficiently stored.
  • Size – The size of each piece of information determines how much space it will occupy in the database. Although the price of storage has come down, still it is not practical to leave an infinite storage space. This information is recognized at the designing stage when building and maintenance of databases happen.
  • Organization – It refers to how the information is grouped and stored as per the user’s convenience and intended use at a particular point in time. Organization of information is stored in such a way that it is on a priority basis and unused or to be used later information is stored separately, making it a comfortable experience for the user.

SQL provides an organized and systematic approach to accessing information through various methods like:

  • Data query
  • Data manipulations (insert, update and delete),
  • Data definition (schema creation and modification),
  • Data access control

Although the SQL database is essentially a declarative language, it includes procedural elements also.

sql database image

Scalability

Scalability is the ability of a system, network, or process, to handle a growing amount of work in an efficient manner or its ability to be enlarged to accommodate that growth. In other words, we can say that it is the ability of a system to optimize its performance level as per the requirement of the system at that stage.

EXAMPLES


Few examples of relational databases using SQL are:-

  • MySQL
  • Oracle
  • Microsoft SQL server
  • Sybase
  • Ingres
  • Access
  • Postgres

Model-

ACID is a concept that is generally used by database professionals for the evaluation of databases and application architectures in the SQL database model to ensure that data is stored in a safe, consistent and robust manner

Here, ACID stands for-

A- Atomicity -Atomicity is an all-or-none proposition. During such transactions between two information either all is saved or none is saved.

C- Consistency The data saved can’t violate any of the database’s integrity.  Interrupted changes are rolled back to ensure the database is placed in a state prior to the change.

I- Isolation – The transaction does not get affected by any other transactions which are happening at other places, this avoids “mid-air collisions.”

D- Durability– Once the transaction happens, any failure or system restart returns the data in an absolute correct form.  Regardless of subsequent system failure, its state remains unaffected.

For a reliable database, all these four attributes should be achieved.

Usage- Which jobs use SQL?

SQL statements are used to perform tasks such as updating and retrieval of data on a database.

A job is a specified series of operations that are sequentially performed by SQL Server Agent. A job performs a wide range of activities, including running Transact- SQL scripts, Command prompt applications, Microsoft ActiveX scripts, Integration Services packages, Analysis Services commands, and queries, or Replication task.

Pros

  • High speed– Using the SQL queries, the user can quickly and efficiently retrieve a larger amount of data from a database.
  • No coding needed– In the standard SQL, it is very easy to manage the database without any substantial coding requirements.
  • Well defined standards– Long established ISO and ANSI standards are strictly followed.
  • Portability– It offers great ease to use in PCs, laptops, servers and even some mobile phones.

Interactive language SQL is used to communicate with greater ease in answering complex queries in a database.

Cons

Along with some benefits, the SQL database comes with certain limitations/ disadvantages:

  • Difficult Interface– SQL has a complex interface making it difficult for the users to access it.
  • Partial Control– Users don’t get full control over the database because of the hidden business rules.
  • Implementation– Some of the databases go to the proprietary extensions to standard SQL for ensuring the vendor lock-in.
  • Cost– The operating cost of a few SQL versions makes it difficult for users to use it.

The average salary of SQL Developer:-

The average annual salary for any SQL developer in the USA is $84,328.

No Sql

NoSQL is a non-relational database management system, that does not require a fixed schema, avoids joins, and is easy to scale. NoSQL database is used for distributed data stores with humongous data storage needs.

NoSQL stands for “not only SQL,” or “Not SQL” an alternative to traditional relational databases where data is placed in tables and schema is carefully designed before the database is built.

A NoSQL database is self-describing, so it does not require a schema. Also, it does not enforce relations between tables in all cases. All its documents are JSON documents, which are complete entities and one can readily read and understand.

A NoSQL database system encompasses a wide range of database technologies that can store structured, semi-structured, unstructured and polymorphic data.

Nosql

NoSQL’ refers to high-performance, non-relational databases that utilize a wide variety of data models. These databases are highly recognized for their ease-of-use, scalable performance, strong resilience, and wide availability.

Database

According to Wikipedia “A NoSQL database provides a mechanism for storage and retrieval of data that is modeled in means other than the tabular relations used in relational databases.”

what is no sql database

NoSql is a cloud-friendly approach to employ for your applications.

Schema For NoSql

The formal definition of a database schema is a set of formulas or sentences called “Integrity constraints” imposed on a database.

NoSql
NOSql SCHEMA

The term “schema” refers to the organization of data as a blueprint of how the database is constructed, construction here refers to the division of database tables in case of relational databases.

Scalability

NoSQL databases are horizontally scalable, which means they can handle increased traffic needs immediately, simply by adding more servers to the database. ‘NoSQL’ databases have the ability to become larger and more powerful, making them a preferred choice for larger or constantly evolving data sets.


Nosql scalability

Examples

Presenting here a list of top 4 NoSQL Databases with their uses:

no sql database examples

Model

‌NoSQL relies upon a softer model known as the BASE model. Here BASE stands for (Basically Available, Soft state, Eventual consistency).

Basically Available: Guarantees the availability of the data.

Usage

NoSQL is used for Big data and real-time web apps.

Pros

No SQL provides ease in availability with rich query language and easy scalability. The following are the main advantages of NoSql databases.

  • Elastic scaling

RDBMS might not scale out easily for commodity clusters, but the new versions of the “NoSQL database” are designed to expand transparently to take benefits from new nodes.

  • Big data

To combat the growing needs of the volumes of data that are being stored, RDBMS capacity has been increased to match these massive volumes. But with transaction rates, constraints of data volumes that can be practically managed by a single RDBMS is getting difficult to handle by organizations/ enterprises worldwide. NoSql systems provide a solution to all this by handling bigger data needs as displayed in Hadoop.

Cons

Every database has certain advantages and some disadvantages as well, listing here a few of the major NoSql limitations:

  • Less Community Support
  • Standardization
  • Interfaces and Interoperability

Average Salary Of NoSql Developer:-

The average annual salary for a NoSql developer in the USA is $72,174.

Major Differences To Understand in SQL and NoSql Database As Per Business Needs

To understand which is the best data management system between Sql Vs NoSql databases for your organization, we must identify the needs of our business and then make an informed decision. In database technology, there’s no one-size-fits-all solution, so it is recommended to analyze SQL Vs NoSql and then decide.

Many businesses rely on both relational and nonrelational databases for different tasks, as NoSQL databases win in speed, safety, cost, and scalability, whereas the SQL database is preferred when the highly structured database is required.

sql vs nosql difference table

One of the key differentiators is that NoSQL is column-oriented, non-relational distributed databases whereas RDBMS is the row-oriented relational database. Also, they are differentiated on the basis of built, type of information they store and how they store

Relational databases are structured, like phone books and Non-relational databases are document-oriented, distributed, like file folders that store everything from a person’s address and phone number to their Facebook and online shopping preferences etc.


pros and cons of sql nosql

The major point of differences in Sql Vs NoSql databases are:

  1. Language– One of the major differences among the SQL database and NoSQL databases is the language. SQL databases use Structured Query Language for defining and manipulating data, making it a widely-used and extremely versatile database. But, it makes it a restrictive language also. SQL requires ‘predefined schemas’ to determine the structure of the data before the user starts working with it. A ‘NoSQL database’ requires a dynamic schema for unstructured data and the data is stored in many different ways, whether it is graph-based, document-oriented, column-oriented, or organized as a KeyValue store. This extreme flexibility in the ‘NoSql database’ allows the user to create documents without having to carefully plan beforehand and define their structure. It gives the flexibility to add fields as you go and vary the syntax from one database to another. It also provides the freedom to give each document its own unique structure.

2. Scalability– Another big difference between SQL and NoSQL is their scalability. In most SQL databases, they are vertically scalable, which means that you can increase the load on a single server by increasing components like RAM, SSD, or CPU. In contrast, NoSQL databases are horizontally scalable, which means that they can handle increased traffic simply by adding more servers to the database. NoSQL databases have the ability to become larger and much more powerful, making them the preferred choice for large or constantly evolving data sets.

sql nosql database

3. Community– Because of the SQL’s advanced and mature useful features in the database management, it has a much stronger, huge and developed community as compared to ‘NoSQL’. Although, NoSQL is growing rapidly its community is not big enough and well defined in comparison to SQL, because it’s relatively new.

4. Structure– Finally in SQL vs NoSQL differences, an important difference in their structures. SQL databases are table-based considered a good option for multi-row transactions like in accounting systems or legacy systems that are built on relational structure. NoSQL databases are key-value pairs, wide-column stores, graph databases, or document-based in structure

List Of Top Companies Using SQL:

  • Hootsuite
  • Gauges
  • CircleCI

List Of Top Companies Using NoSQL:

  • Uber
  • Airbnb
  • Kickstarter

Conclusion:

One of the most important decisions for your businesses is what database to go for as per the requirement. Many times it so happens that businesses require both the databases at various stages of an application. The onus is on the developer to recognize the right database for a certain application and deploy it as per the need on the basis of query and scalability needs.

  • SQL databases are suitable for transactional data where structural change is not required frequently or does not happen at all. Also, data integrity and durability is of paramount importance. Additionally, it is found useful for faster analytical queries.
  • NoSQL databases provide better flexibility and scalability yielding high performance with high availability. Also, it is better for big data and real-time web applications.

Categories
Backend Developer Database Programming React Developers

Hooks, Getting in a New Relationship

Introducing React Hooks


In 2018, at the React Conference “Hooks” was officially Introduced to React.

Hooks arrived as a savior for developers who were struggling in maintaining hundreds of states for hundreds of components.

They let you use state and other React features without writing a class. Now, you can kick out classes from your components.

No need to worry, There are no plans to remove classes from React permanently, yet

You can adopt Hooks gradually,
Hooks work side-by-side with existing code so there is no rush to migrate to Hooks.

You don’t have to learn or use Hooks right now if you don’t want to.

WHY GO FOR HOOKS?

You might be thinking why you need to learn one more feature? The answer is here:

  • It helps when you need to maintain too many components and states.
  • Completely opt-in.
    You can try Hooks in a few components without rewriting any existing code.
  • A “wrapper hell” of components surrounded by layers of providers, consumers, higher-order components, render props, and other abstractions. While we could filter them out in DevTools, this points to a deeper underlying problem: React needs a better primitive for sharing stateful logic, here Hooks made an appearance.
  • With Hooks code Reusability is improved, you can extract stateful logic from a component so it can be tested independently and reused. Hooks allow you to reuse stateful logic without changing your component hierarchy. This makes it easy to share Hooks among many components or with the community.
  • render props and higher-order components try to solve some problems but make code harder to follow, because it requires to restructure your components.
  • components might perform some data fetching in componentDidMount and componentDidUpdate. However, the same componentDidMount method might also contain some unrelated logic that sets up event listeners, with cleanup performed in componentWillUnmount. Mutually related code that changes together gets split apart, but completely unrelated code ends up combined in a single method. This makes it too easy to introduce bugs and inconsistencies.
  • It’s not always possible to break these components into smaller ones because the stateful logic is all over the place. It’s also difficult to test them. This is one of the reasons many people prefer to combine React with a separate state management library.
  • class components can encourage unintentional patterns that make these optimizations fall back to a slower path

How Hooks Affect the Coding Style

  • Say bye! to class
Without Hooks:

Class Components

class Clock extends React.Component {
    ...
    ...
    render() {
        return (
            <div>
                <h1>...something...</h1>
            </div>
        );
    }
}
With Hooks:

Function Components

function Example() {
    ... // Hooks can be used here
    ...
    render() {
        return (
            <div>
                <h1>...something...</h1>
            </div>
        );
    }
}
OR like this:
function Example = () => {
    ... // Hooks can be used here
    ...
    render() {
        return (
            <div>
                <h1>...something...</h1>
            </div>
        );
    }
}

> you can also pass props to the function:

function Example(props) {
    ... // Hooks can be used here
    ...
}
OR like this:
function Example = (props) => {
    ... // Hooks can be used here
    ...
}

props can be accessed like this -> const v = props.value

  • Creating a local state
Without Hooks:
const state = {
    x: 10,
    y: 'hello',
    z: {
        word: "world!"
    }
}
With Hooks:

useState is used to set the initial value for a local state.

// this is How we declare a new state variable
const [color, setColor] = useState('Yellow');

// declaring multiple state variables
const [x, setX] = useState(10);
const [y, setY] = useState('hello');
const [z, setZ] = useState([{
    word: "world!",     
}]);
  • Accessing state: a Breakup With this
Without Hooks:
constructor(props) {
    this.state = { text: 'demo' };
}

render() {
    return (
        <div>
            <h1>This is { this.state.text }</h1>
        </div>
    );
}
With Hooks:

While using hooks, state variables can be accessed directly

const [text, setText] = useState('demo');

render() {
    return (
        <div>
            <h1>This is { text }</h1>
        </div>
    );
}
  • Changing the State
Without Hooks:
...
this.state = {
    a: 1,
    b: 2,
    fruit: 'apple'
}

...
{
    this.setState({
        ...state,
        fruit: 'orange'
    });
}
With Hooks:
const [fruit, setFruit] = useState('apple');

...
{
    setFruit('orange')
}
  • Effect of the Effect Hook
  • React runs the effects after every render, including the first render.
  • With useEffect() we can run a script after each update or after a particular change.
  • Lifecycle methods componentDidMount, componentDidUpdate or componentWillUnmount can be replaced with useEffect()
// To run with each Update
useEffect(() => {
    // Do something
});


// run only when value of "color" is changed
useEffect(() => {
    // Do something
}, [color]);


// run only on first render
useEffect(() => {
    // Do something
}, []);

Let’s see some usages, in lifecycle methods
— ComponentDidMount

Without Hooks:
componentDidMount() {
    // do something
    const cat = "tom";
    this.setState({
        ...state,
        animal: cat
    });
}
With Hooks:
useEffect(() => {
    // Do Something
    const cat = "tom";
    setAnimal(cat);
}, []);

— ComponentDidUpdate

Without Hooks:
componentDidUpdate() {
    // do something
    const cat = "tom";
    this.setState({
        ...state,
        animal: cat
    });
}
With Hooks:
useEffect(() => {
    // Do Something
    const cat = "tom";
    setAnimal(cat);
})

above snippet will run the code at every update including the first render acting as a combination of componentDidMount and componentDidUpdate, if you want to prevent it from running on first render, then it can be done by keeping a check of first render, like this:

const [isFirstRender, setIsFirstRender] = useState(true);

useEffect(() => {
    if (isFirstRender) {
        setIsFirstRender(false);
    } else {
        // do Something
        const cat = "tom";
        setAnimal(cat);
    }
}

— ComponentWillUnmount

Without Hooks:

componentWillUnmount() {
    // Do Something
}
With Hooks:

Just return a function ( named or anonymous ) for cleanup, that we do in ComponentWillUnmount

useEffect(() => { 
    return () => {
        // Do something
    }
});
  • Getting the context with the Context Hook

useContext() takes a context object as the parameter and returns the corresponding context values at that time. Refer to the example below for a better understanding.

// for example, We have
const flowers = {
    sunflower: {
        petals: 25,
        color: "yellow"
    },
    daisy: {
        petals: 5,
        color: "white"
    },
    rose: {
        petals: 30,
        color: red
    }
};


// Creating our context
const MyContext = React.createContext( flowers.rose );


// Wrappin the component with <MyContext.Provider>
function App() {
    return (
        <MyContext.Provider value={ flowers.sunflower }>
            <MyComponent />
        </MyContext.Provider>
    )
}

The current context value is determined by the value of the value prop passed in the nearest <MyContext.Provider> in which the component is wrapped.

// ... somewhere in our function component ...
const flower = useContext(MyContext);

Now the flower will have the value of rose:
{ petals: 30, color: "red" }
and can be used as
<p>Colour of rose is { flower.color }.</p>
It will run each time when the context is updated

You must have got the ‘context‘ of this blog if you are still here, kindly have a look at “Some rules to remember” below:

Some rules to remember

  • never be conditional with Hooks:
    don’t call hooks inside loops or conditions, call Hooks at the Top level
  • don’t call hooks from nested functions:
    call only from React Function components or custom hooks
    More details can be found in official React docs, available here

More about Hooks

More Hooks

Some other commonly used Hooks are:

Custom Hooks

A custom Hook is a function whose name starts with ”use” and that may call other Hooks and, lets you extract component logic into reusable functions.

Let’s create a custom Hook useColor that returns the color of the flower whose ID is passed as argument:

function useColor(flowerID) {
    const [color, setColor] = useColor(null);

    useEffect(() => {
        /*    Extract the value of colour of the flower from the database and set the value of color using setColor()    */
    });

    return color;
}

Now, we can use our custom hook,

{
    // To get the colour of the flower with ID = 10
    const color = useColor(10);
}

Learn more about how to create the custom hooks in detail.

See official docs for React Hooks.

Categories
Backend Developer Database Development Top Coder

TypeORM With NEST JS Basic Tutorial

In this article, we will be using TypeORM with Nest Js to integrate database with our application. But before starting with TypeORM, let’s have a brief look over the concept of Object-relational mapping(ORM).

Object-relational mapping as a technique for converting data between incompatible type systems using object-oriented programming languages. In other words, ORM is a programming technique in which a metadata descriptor is used to connect object code to a relational database.

Source Wikipedia

Object code is written in object-oriented programming (OOP) languages such as C++, JAVA, etc. We will be using TypeScript for creations of our object-oriented programming.

In addition to the data access technique, ORM also provide
simplified development because it automates object-to-table and table-to-object conversion, resulting in lower development and maintenance costs.

Now, when we have a good idea about what is the notion of ORM is, let’s understand what TypeORM is :-

TypeORM: TypeORM is an ORM that can run in NodeJS, Browser, Cordova, PhoneGap, Ionic, React Native, NativeScript, Expo, and Electron platforms and can be used with TypeScript and JavaScript (ES5, ES6, ES7, ES8).

Topics:

  1. Creating a model( or Table ).
  2. Primary / Auto-generation column.
  3. Relationship between two or more models.
  4. Our Project.

Creating a model/ Table

The first step in the database is to create a table. With TypeORM, we create database tables through models. So models in our app will be our database tables.

Now create a sample model “Cat” for a better understanding.


export class Cat {
    id: number;
    name: string;
    breed: string;
    age: string;
}

Note: The database table is not created for each model but only for those models which are declared as entities. To declare a model as an entity, we just need to add @Entity() decorator before the declaration of the Class defining our model.

In addition to this, we should ideally have columns in our model now because the table which will be generated (because of the model being declared as an entity now) makes no sense without any column in it. To add a data member of a model as a column, we need to decorate a data member with a @Column() decorator.

Let us modify our above model of ‘Cats’ by adding ‘@Entity()’ and ‘@Column()’ decorator.


@Entity()
export class Cat {

    @Column()
    id: number;

    @Column()
    name: string;

    @Column()
    breed: string;
    
    @Column()
    age: string;

}

Primary / auto-generated primary column

For creating a column as a primary key of the database table, we need to use @PrimaryColumn() decorator instead of @Column() decorator. And for the primary column to be self-generated, we need to use @PrimaryGeneratedColumn() instead of @PrimaryColumn().

By making ‘id’ in ‘Cat’ as auto-generated primary key, our Cat model will look like this:


@Entity()
export class Cat {

    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    name: string;

    @Column()
    breed: string;
    
    @Column()
    age: string;

}

Relationship between two or more models

A relationship, in the context of databases, is a situation that exists between two relational database tables when one table has a foreign key that references the primary key of the other table. Relationships allow relational databases to split and store data in different tables while linking disparate data items.

There are 3 types of relationships in relational database design :-

  • One-to-One (implemented by @OneToOne() decorator)
  • One-to-Many / Many-to-One (implemented by @OneToMany() decorator )
  • Many-to-Many (implemented by @ManyToMany() decorator)
One-to-One
One-to-Many
Many-to-Many

Our Project

In this section, we will create a NestJS project in which we will have three tables/entities as follows:

  • UserEntity
  • BookEntity
  • GenreEntity

Relationships between the entities:

  • UserEntity and BookEntity: One-To-Many
  • BookEntity and GenreEntity: Many-To-Many

In simple words, a user can have many books and each book can belong to more than one Genre.

For now, we will create the above-mentioned entities as follows without any relationship between them as follows:

MyProject/db/user.entity.ts


import { Entity, PrimaryGeneratedColumn, Column, BaseEntity, OneToMany } from 'typeorm';
import BookEntity from './book.entity';
@Entity()
export default class UserEntity extends BaseEntity {

  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 500 })
  name: string;
}

MyProject/db/book.entity.ts


import { Entity, PrimaryGeneratedColumn, Column, BaseEntity, ManyToOne, ManyToMany, JoinTable } from 'typeorm';
import UserEntity from './user.entity';
import GenreEntity from './genre.entity';

@Entity()
export default class BookEntity extends BaseEntity 
{
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 500 })
  name: string;
}

MyProject/db/genre.entity.ts


@Entity()
export default class GenreEntity extends BaseEntity {

  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  type: string;

}

For setting up the relation between UserEntity and BookEntity, we have to add the following code in UserEntity and BookEntity Class as follows:

MyProject/db/user.entity.ts


// 1:n relation with bookEntity 
  @OneToMany( type => BookEntity , book => book.user)
  books: BookEntity[];

type => BookEntity is a function that returns the class of the entity with which we want to make our relationship.

book => book.user states which column to be used by ‘BookEntity’ to get the associated user.

Now, we have set a One-to-Many relationship from the ‘UserEntity’ side. As One-to-Many is complimentary with Many-to-One, we should state the ‘Many-to-One’ relationship from BookEntity to UserEntity.

MyProject/db/book.entity.ts


// n:1 relation with books
  @ManyToOne(type => UserEntity, user => user.books)
  user: UserEntity;

Similarly, to make a many-to-many relationship between BookEntity and GenreEntity, we have to add the following code:


// n:n relation with genre
  @ManyToMany(type => GenreEntity)
  @JoinTable()
  genres: GenreEntity[];

Here, ‘@JoinTable()’ decorator states that in a many-to-many relationship in BookEntity and GenreEntity, the ownership lies in the BookEntity side.

Now we are done with almost everything related to database and TypeORM. The only thing that remains is to establish a connection with the database. For this purpose, we have to create an ‘ormconfig.json’ file and add the following JSON code in it.

MyProject/ormconfig.json


{
  "type": "sqlite",
  "database": "./database.sqlite",
  "synchronize": "true",
  "entities": [
    "dist/db/entity/**/*.js"
  ],
  "cli": {
    "entitiesDir": "src/db/entity"
  }
}

The first line in the above JSON object specifies that the database we are using is ‘SQLite’.

Now we have to create the NEST controllers and services to handle the requests.

Here are the three DataTransferObjects we will be using in the further code:

MyProject/User/dto/create-user.dto.ts


export default class CreateUserDto {
  readonly name: string;
  readonly books: number[] ;
}

MyProject/User/dto/create-book.dto.ts


export default class CreateBookDto {
  readonly name: string;
  readonly userID: number;
  readonly genreIDs: number[];
}

MyProject/User/dto/create-genre.dto.ts


export default class CreateGenreDto {
  readonly type: string;
}

Below are the Controllers and Services for Users, Books, and Genres which will be handling the requests.

Users

MyProject/User/user.controller.ts


import { Body, Controller, Get, ParseIntPipe, Post, Put } from '@nestjs/common';
import { UserServices } from './user.services';
import CreateUserDto from './dto/create-user.dto';

@Controller('users')
export class UserController {
  constructor(private readonly usersServices: UserServices) {}

//'postUser()' will handle the creating of new User
  @Post('post')
  postUser( @Body() user: CreateUserDto) {
    return this.usersServices.insert(user);
  }
// 'getAll()' returns the list of all the existing users in the database
  @Get()
  getAll() {
    return this.usersServices.getAllUsers();
  }

//'getBooks()' return all the books which are associated with the user 
// provided through 'userID' by the request  
  @Get('books')
  getBooks( @Body('userID', ParseIntPipe) userID: number ) {
    return this.usersServices.getBooksOfUser(userID);
  }
}

Myproject/User/user.service.ts


import { Injectable } from '@nestjs/common';
import UserEntity from '../db/entity/user.entity';
import CreateUserDto from './dto/create-user.dto';
import BookEntity from '../db/entity/book.entity';
import {getConnection} from "typeorm";

@Injectable()
export class UserServices {

  async insert(userDetails: CreateUserDto): Promise<UserEntity> {
    const userEntity: UserEntity = UserEntity.create();
    const {name } = userDetails;
    userEntity.name = name;
    await UserEntity.save(userEntity);
    return userEntity;
  }
  async getAllUsers(): Promise<UserEntity[]> {
    return await UserEntity.find();
  }
  async getBooksOfUser(userID: number): Promise<BookEntity[]> {
    console.log(typeof(userID));
    const user: UserEntity = await UserEntity.findOne({where: {id: userID}, relations: ['books']});
    return user.books;
  }
}

Myproject/User/user.module.ts


import { Module } from '@nestjs/common';
import { UserServices } from './user.services';
import { UserController } from './user.controller';
@Module({
  imports: [],
  controllers: [UserController],
  providers: [UserServices],
})
export class UserModule {}

Genre

MyProject/Genre/genre.controller.ts


import { Body, Controller, Get, Post } from '@nestjs/common';
import GenreServices from './genre.services';
import CreateGenreDto from './dto/create-genre.dto';

@Controller('genre')
export default class GenreController {
  constructor(private readonly genreServices: GenreServices) {}
  @Post('post')
  postGenre( @Body() genre: CreateGenreDto) {
    return this.genreServices.insert(genre);
  }
  @Get()
  getAll() {
    return this.genreServices.getAllGenre();
  }
}

MyProject/Genre/genre.services.ts


import { Injectable } from '@nestjs/common';
import CreateGenreDto from './dto/create-genre.dto';
import GenreEntity from '../db/entity/genre.entity';

@Injectable()
export default class GenreServices {
    async insert(genreDetails: CreateGenreDto): Promise<GenreEntity> {

    const genreEntity: GenreEntity = GenreEntity.create();
    const {type} = genreDetails;

    genreEntity.type = type;
    await GenreEntity.save(genreEntity);
    return genreEntity;
  }
  async getAllGenre(): Promise<GenreEntity[]> {
        return await GenreEntity.find();
  }
}

MyProject/Genre/genre.module.ts


import { Module } from '@nestjs/common';
import GenreServices from './genre.services';
import GenreController from './genre.controller';
@Module({
  imports: [],
  controllers: [GenreController],
  providers: [GenreServices],
})
export default class GenreModule {}

Books


MyProject/Books/books.controller.ts

import BookEntity from '../db/entity/book.entity';
import CreateBookDto from './dto/create-book.dto';
import UserEntity from '../db/entity/user.entity';
import { createQueryBuilder, getConnection } from 'typeorm';
import GenreEntity from '../db/entity/genre.entity';

export class BooksService {

  async insert(bookDetails: CreateBookDto): Promise<BookEntity> {
    const { name , userID , genreIDs } = bookDetails;
    const book = new BookEntity();
    book.name = name;
    book.user = await UserEntity.findOne(userID) ;
    book.genres=[];
    for ( let i = 0; i < genreIDs.length ; i++)
    {
             const genre = await GenreEntity.findOne(genreIDs[i]);
             book.genres.push(genre);
    }
    await book.save();
    return book;
  }
  async getAllBooks(): Promise<BookEntity[] > {
    // const user: UserEntity = await UserEntity.findOne({where: {id: 2}, relations: ['books']});
    return BookEntity.find();
  }

MyProject/Books/books.module.ts


import { Module } from '@nestjs/common';
import { BooksService } from './books.service';
import BooksController from './books.controller';
@Module({
  imports: [],
  controllers: [BooksController],
  providers: [BooksService],
})
export default class BooksModule {}

Now, finally, this is the time to integrate everything with ‘app.module.ts’


import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserModule } from './User/user.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import UserEntity from './db/entity/user.entity';
import BooksModule from './Books/books.module';
import GenreModule from './Genre/genre.module';
import BookEntity from './db/entity/book.entity';
import GenreEntity from './db/entity/genre.entity';

@Module({
  imports: [UserModule ,
            BooksModule,
            GenreModule,
    TypeOrmModule.forFeature(
      [UserEntity, BookEntity , GenreEntity],
    ),

    TypeOrmModule.forRoot(),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Categories
Backend Developer Cloud Database Python

The complete guide for Python and Django-Part1 Python

Note: In this tutorial, we will be using Python3 instead of Python2. The reason for this choice is that Python2 is slowly getting deprecated from the development world and the developers are developing new libraries strictly for the use with Python3.

Starting with Python3

Content:

  1. Installation
  2. DataTypes
  3. Comparison operators
  4. Control flow:
    1. IF ELIF and ELSE statements
    2. WHILE
    3. FOR loop statements
  5. Functions
  6. Object-Oriented Programming
  1. Installations:

Mac installation: https://docs.python-guide.org/starting/install3/osx/

Linux Installation: https://docs.python-guide.org/starting/install3/linux/

Windows Installation: https://docs.python.org/3/using/windows.html#installation-steps

2. Data Types:

Integer

In Python 3, there is effectively no limit to how long an integer value can be. Of course, it is constrained by the amount of memory your system has, as are all things, but beyond that an integer can be as long as you need it to be:

a = 123123123123123123123123123123123123123

Notice that we don’t have to specify the type of the variable ‘a’ in the above code. type of the variable will be dynamically handled by python on the basis of the value being stored in the variable.


Floating Point:

The float type in Python designates a floating-point number. float values are specified with a decimal point. Optionally, the character e or E followed by a positive or negative integer may be appended to specific scientific notation:

a=2.513
print( type(a) )

In the above code, the last line will print ‘float’ , which is the type of variable ‘a’.

Complex:

We need to import “cmath” to use this data type.

Let us look at the code below and try to understand how it works.

#importing cmath 
import cmath 

#initialising the variable 'z' with the value '2+3i'
z=complex(2,3)

#accessing the real part of variable 'z'
print("real part of z is: " + ,end="")
print(z.real)

#accessing the imag part of 'z'
print("imaginary part of z is: " + ,end="")
print(z.imag)

Sets:

Sets represent the mathematical notion of sets. Sets are mutable, iterable and don’t have any duplicate value. Python provides us, along with ‘set’ datatype, the mathematical functions associated with the sets such as intersection, union, difference, etc.

Let us look at the following code to understand the sets better.

#creating a set 'mySet' with values 1, 2 , and 3
mySet = set([1, 2, 3]) 
  
# Adding an element to mySet by the function 'add()' 
mySet.add(6) 

print("mySet") 
print(mySet) 

#creating another set with the name 'anotherSet'
anotherSet = set([3,4,5])


union_of_sets = mySet.union(anotherSet)

#this will print {1, 2, 3, 4 ,5 ,6}
print(union_of_sets)

intersection_of_sets = mySet.intersect(anotherSet)

#this will print the set {3}
print(intersection_of_sets)

difference_of_two_sets = mySet.difference(anotherSet)

#this will print {1, 2 , 6}
print(difference_of_sets)

Dictionary:

In Python, a Dictionary can be created by placing a sequence of elements within curly {} braces, separated by ‘comma’. Dictionary holds a pair of values, one being the Key and the other corresponding pair element being its Key:value. Values in a dictionary can be of any datatype and can be duplicated, whereas keys can’t be repeated and must be immutable.

# Creating an empty Dictionary 
Dict = {} 
print("Empty Dictionary: ") 
print(Dict) 
  
# Adding elements into the dictionary 
Dict[2] = 'alpha'
Dict[3] = 1

#this will print { 2: 'alpha'  , 3: 1}
print(Dict) 
  
# Updating existing Key's Value 
Dict[2] = 'Welcome'

the following line will print { 2: 'welcome'  , 3: 1}
print(Dict) 
  
# Adding Nested Key value to Dictionary 
Dict[5] = {'Nested' :{'1' : 'Life', '2' : 'Geeks'}} 
print("\nAdding a Nested Key: ") 
print(Dict) 

List:

A list is created by placing all the items (elements) inside a square bracket [ ], separated by commas.

It can have any number of items and they may be of different types (integer, float, string etc).


# creating a empty list
my_list = []


my_list = [1, 2, 3]

#overwriting the privious list [1 , 2 ,3 ] with the new list [1,"Hello",3.4]
my_list = [1, "Hello", 3.4]

#adding values to the list
my_list.append(5)

#now the new list is [1,"Hello",3.4, 5]
print (my_list)

my_list = ['a','b','c','d','e']

# Output: e
print(my_list[-1])

# Output: a
print(my_list[-5])

Negative indexing:

Tuple:

A tuple in Python is similar to a list. The difference between the two is that we cannot change the elements of a tuple once it is assigned whereas, in a list, elements can be changed. In other words, tuples are immutable.

A tuple is created by placing all the items (elements) inside parentheses(), separated by commas. The parentheses are optional, however, it is a good practice to use them.

A tuple can have any number of items and they may be of different types (integer, float, list, string, etc.). Let us look at the following code to understand tuples in a better way:

# Empty tuple
myTuple = ()
print(myTuple)  # Output: ()

# Tuple having integers
myTuple = (1, 2, 3)
print(myTuple)  # Output: (1, 2, 3) 

# tuple with mixed datatypes
myTuple = (1, "Hello", 3.4)
print(myTuple)  # Output: (1, "Hello", 3.4)  

# nested tuple
myTuple = ("mouse", [8, 4, 6], (1, 2, 3))

# Output: ("mouse", [8, 4, 6], (1, 2, 3)) 
print(myTuple)

A tuple can also be created without using parentheses. This is known as tuple packing. For instance:

my_tuple = "Hello", 1.2, 6
print(my_tuple)   # Output: "hello", 1.2, 6 

Tuple unpacking is also possible

my_tuple = "Hello", 1.2, 6

# unpacking the tuple
a, b, c = my_tuple

print(a)      # 3
print(b)      # 4.6 
print(c)      # dog 

Strings:

Strings are arrays of bytes representing Unicode characters. However, Python does not have a character data type, a single character is simply a string with a length of 1. Square brackets can be used to access elements of the string.

Slicing in a string:

String1 = "PythonIsFun"
  
print(String1) 

# Printing 3rd to 12th character  using slicing
print("\nSlicing characters from 3-12: ") 
print(String1[3:12]) 
  
# Printing characters between  
# 3rd and 2nd last character 
print("\nSlicing characters between " +
    "3rd and 2nd last character: ") 
print(String1[3:-2]) 

Boolean

The bool() method is used to return or convert a value to a Boolean value i.e., True or False, using the standard truth testing procedure.

x=1
y=2
z=bool(x==y) #this statement will assign False to z as x is not equal to y

x=True
print( bool(x)) #this statement will print 'True' as x is true

x=None
print( bool(x)) #this statement will print 'False' as x is None

x={}
print( bool(x)) #this statement will print 'False' as x is None
#using bool() to find if the number is less than 5 or not
num=7
if(bool(num<5)):
    print('num is less than 5')
else:
    print('num is not less than 5')

3. Comparison Operator/Relational Operators

Comparison operators are used to compare the two values and establish a relationship between them. The expression always evaluates to True or False.

These are the following types of comparison operators used in Python3:

  • == (equal to)
  • != (not equal to)
  • < (less than)
  • > (greater than)
  • >= (greater than or equal to)
  • <= (less than or equal to)


a = 21
b = 10

# '==' operator 
if ( a == b ):
   print ("a is equal to b")
else:
   print ("a is not equal to b")

# '!=' operator
if ( a != b ):
   print ("a is not equal to b")
else:
   print ("a is equal to b")

# '<' operator
if ( a < b ):
   print ("a is less than b" )
else:
   print ("a is not less than b")

# '>' operator
if ( a > b ):
   print ("a is greater than b")
else:
   print ("a is not greater than b")


#swapping of values
a,b = b,a 

# '<=' operator
if ( a <= b ):
   print ("a is either less than or equal to  b")
else:
   print ("a is neither less than nor equal to  b")

# '>=' opeartor
if ( b >= a ):
   print ("b is either greater than  or equal to b")
else:
   print ("b is neither greater than  nor equal to b")

4. Control Flow

(a) IF ELIF ELSE

Syntax:

if expression:
   statement(s)
elif expression:
   statement(s)
else:
   statement(s)

We can add as many elif as we want in-between if and else block. The count of elif blocks can also be zero. In that case, the else block will immediately follow the if block.

The following code illustrates the use of if elif and else

amount = int(input("Enter amount: "))

if amount<1000:
   discount = amount*0.05
   print ("Discount",discount)
elif amount<5000:
   discount = amount*0.10
   print ("Discount",discount)
else:
   discount = amount*0.15
   print ("Discount",discount)
    
print ("Net payable:",amount-discount)

Output:

Enter amount: 3000
Discount 300.0
Net payable: 2700.0

(b) WHILE LOOP

In Python, while loops are constructed like so:

while [a condition is True]:
    [do something]

The something that is being done will continue to be executed until the condition that is being assessed is no longer true.

Here is the code to illustrate the use of a while loop:

count = 0
while (count < 3):     
    print(count)
    count = count + 1

Output:

0
1
2

(c) FOR LOOP

Syntax:

for iterator_var in sequence:
    statements(s)

Let us look at the following code to see understand the for loop better:

s = "HelloWorld"
for i in s : 
    print(i) 

Output:

H
e
l
l
o
W
o
r
l
d

Here is another piece of code to traverse the dictionary

print("\nDictionary traversal")    
d = dict()  
d['first'] = 100
d['second'] = 200
for i in d : 
    print("%s  %d" %(i, d[i]))

Output:

first  100
second  200

5. Functions

A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing.

Here is a syntax to declare a function:

def function_name( parameters ):
   #some statements
   return [expression] #the return statement is optional

For example, let us create a simple function which computes the sum of two values which are passed to it (as a parameter). We will name that function ‘sum’.

def sum(x , y):
    ans=x+y
    return ans

Calling the defined function

We can call the defined function, like the above , as follows:

result = sum(4, 5) # the function 'sum' will return 9 which will be stored in 
                   # the variable 'result'  
print(result)      # this statement will print '9'

Output:

9

6. Object-Oriented Programming / OOP

To understand OOP, we need to understand what is class and object.

Classes are like a blueprint or a prototype that you can define to use to create object.

We define classes by using the class keyword, similar to how we define functions by using the def keyword.

Learn about advantages of python over other leading languages

Syntax:

class Class_name:
    # statements to define data members and methods of this class 

Let us create an empty class ‘Person’ for now.

class Person():
    pass

Important terms related to Class:

  • The Constructor Method: This is the method that executes first when we create a new instance of that class. We always have to name this function as ‘__init__‘.
class Person():
    def __init__(self):
        print('This is the constructor method')
  • Self: The argument to the __intit__ () functions is the keyword ‘self‘, which is a reference to objects that are made based on this class. To reference instances (or objects) of the class, self will always be the first parameter, but it need not be the only one.
  • Methods: Method is a special kind of function that is defined within a class. A class can have any number of methods. __init__() is also one of the methods.
  • Attributes: Attributes are data stored inside a class or instance and represent the state or quality of the class or instance. In short, attributes store information about the instance.

Let us add two attributes ‘name’ and ‘age’ to our class ‘Person’. We can do that using the __init__() function. Here is the code:

class Person():
    def __init__(self, name , age):
        self.name=name
        self.age=age

Now, as the __init__() function is receiving ‘name’ and ‘age’ attribute, it becomes compulsory to pass the name and age while creating the instance /object ‘Person’ object. This is how we can create an object of class Person

#Creating the Person 'p' with the name 'Susan' and age 22
p=Person('Susan' , 22)
print(p.name)
print(p.age)

As we can notice from the above code, we can access the attributes associated with the object using the . operator.

Let us now add a method to our class ‘Person’ which increments the age of that person by one.

We will call that method ‘IncreaseAge()’.

class Person():
    def __init__(self, name , age):
        self.name=name
        self.age=age
    def IncrementAge(self ):
        self.age= self.age+1;
        
p=Person('Susan' , 22)
print('The age before calling the method IncrementAge')
print(p.age)

print('The age after calling the method IncrementAge')
p.IncrementAge();
print(p.age)

Output:

The age before calling the method IncrementAge
22
The age after calling the method IncrementAge
23

Inheritance in classes

Inheritance is one of the mechanisms to achieve the same. In inheritance, a class (usually called superclass or Base Class) is inherited by another class (usually called subclass or Derived Class). The subclass adds some attributes to a superclass.

Let us understand it by extending our Person class by creating a Student class. A student is also a person with a name and the age but also has some additional properties such as roll number.

So basically, the Student class will inherit the ‘name’ and ‘age’ attribute from its base class which is Person.

This is the code to illustrate the concept of inheritance:

class Person():
    def __init__(self, name , age):
        self.name=name
        self.age=age
    def IncrementAge(self ):
        self.age= self.age+1;


#the Student class inherits the Person class
class Student(Person):
    def __init__(self,name , age ,RollNo ):
        Person.__init__(self , name , age)
        self.rollNumber= RollNo
    


print("student's information")

s=Student('Madara' , 10 , 123)
print(s.rollNumber)
print(s.name)
print(s.age)
s.IncrementAge()
print(s.age)

Output:

student's information
123
Madara
10
11

Notice that, the Student class has acquired the ‘name’ and ‘age’ property from the Person class. The ‘IncrementAge()‘ method can also be used with the Student object.

Part 2 of this article will be published soon.

Categories
Backend Developer Database Javascript Node

25 Interview Questions on Node.js

Here we listed down the most asked interview questions on Node js so that you don’t have to go anywhere. This is a one-stop destination for all your queries. We provide you the top 25 interview questions on Node js so you can ace your interview. Let’s just look at the questions below.

1. What is Node js?

The first and most asked question is what is Node js?. Node js is an open-source server environment that uses javascript to make web software that is computationally simple but is easily accessed. It works really fast and can run on different platforms like Windows, Linux, Mac OsX, etc

2. What are some key benefits to Nodejs?

There are numerous benefits of Node js which are explained as follows.

  1. It is fast because it is built on Google chrome’s V8 JavaScript engine which makes it really fast.
  2. Node js has no buffering and no blocking while working. It output the data in chunks.
  3. It is Asynchronous meaning Nodejs never stops for an API to return the data. It is ready to take the next request.

3. Is Node js single-threaded? If yes, then why?

Well yes and actually no. NodeJS is single-threaded since no two functions can be run at the same time. Although, a running program called a process can have multiple threads. NodeJS runs only one program at a time to implement its asynchronous nature of program execution hence a single-threaded server environment but can a program can use multiple threads internally to yield optimal performance hence a multi-threaded server environment.

4. What type of applications you can build using Node js?

  • Streaming apps
  • Chat applications
  • Internet of things
  • Microservices
  • Collaboration tools
  • You just name it and we can build it using Node.js

5. How the content of a file is read by Node js?

The NodeJS’s fs (file-system) module provides an API to interact with the system files. The files can be read with multiple methods available to us. In the example below, we will be using the readfile method of fs module to read the contents of a file.

var fs = require(‘fs’);

fs.readFile(‘DATA’, ‘utf8’, function(err, contents) {

    console.log(contents);

});

console.log(‘after calling readFile’);

if you want to know in synchronous manner then have a look in this sample

var fs = require(‘fs’);

var contents = fs.readFileSync(‘DATA’, ‘utf8’);

console.log(contents);

 

6. Discuss the streams in Nodejs? And what are the different types of streams?

Streams are something that allows the reading and writing of data from source to destination in a continuous process.

Streams are of 4 types

·         <Readable> that promotes reading operation

·         <Writable> that promotes writing operation

·         <Duplex> that promotes above both

·         < Transform> is a kind of duplex stream which does the computation based on available input.

7. What is closure?

A closure is a function that is sustained in another scope that has access to all other variables in the outer scope.

8. Does Zlib use in Nodejs? If yes, then why?

Yes, Zlib used in Nodejs and Zlib was written by Jean-loup Gailly and Mark Adler. It is a cross-platform data compression library. You need to install a node- Zlib package in order to use Zlib in Nodejs. A sample is given below which shows the code to use Zlib. 

var Buffer = require(‘buffer’).Buffer;

var zlib = require(‘zlib’);

var input = new Buffer(‘lorem ipsum dolor sit amet’);

var compressed = zlib.deflate(input);

var output = zlib.inflate(compressed);

9. Discuss the globals in Node.js?

Globals basically comprise three words which are Global, Process and Buffer. Let’s discuss it one by one.

Global–  As the name is suggesting Global is something which has many things under its umbrella. So it’s a namespace object and act as an umbrella for all other objects < global>

 Process– It is a specified type of Global and can convert Asynchronous function into an Async callback. It can be linked from anywhere in the code and it basically gives back the information about the application.

 Buffer– Buffer is something that is known as a class in Nodejs to tackle the binary data.

 

10. Differentiate between Nodejs and Ajax?

Ajax is used on a specific section of a page’s content and update that specific portion rather than updating the full part of the content.

Nodejs, on the other hand, used for developing client-server applications. Both of the above serve different purposes and these are the upgraded implementation of JavaScript.

11. What is Modulus in Node Js?

Modules are a reusable block of code whose existence doesn’t impact alternative code in any means. it’s not supported by Javascript. Modules come in ES6. Modules are necessary for Maintainability, Reusability, and Namespacing of Code.

12. What do you mean by an event loop and how does it work?

An event loop tackles all the callbacks in any application. It is the vital component of Nodejs and the main reason behind the non- blocking I/O. Since Node.js is associate event-driven language, you’ll be able to simply attach an observer to an occurrence so once the event happens the callback is executed by the precise observer.

13. What is callback hell?

Callback Hell is additionally referred to as the Pyramid of Doom. it’s a pattern caused by intensively nested callbacks that square measure unreadable and unwieldy. It usually contains multiple nested request functions that successively build the code exhausting to browse and correct. it’s caused by improper implementation of the asynchronous logic.

query(“SELECT clientId FROM clients WHERE clientName=’picanteverde’;”, function(id){

  query(“SELECT * FROM transactions WHERE clientId=” + id, function(transactions){

    transactions.each(function(transac){

      query(“UPDATE transactions SET value = ” + (transac.value*0.1) + ” WHERE id=” + transac.id, function(error){

        if(!error){

          console.log(“success!!”);

        }else{

          console.log(“error”);

        }

      });

    });

  });

});

14. What are the types of API functions in Nodejs?

There are mainly two types of API functions, one is blocking function and the other is non- blocking function.

Blocking function:  These functions implement synchronously and all other code is blocked from implementing until an I/O event that is being waited occurs.

For instance

const fs = require(‘fs’);

const data = fs.readFileSync(‘/file.md’); // blocks here until file is read

console.log(data);

// moreWork(); will run after console.log

Non-blocking Functions: These functions implement ASynchronoulsy and in this multiple, I/O calls can be executed without being waited for.

For instance

const fs = require(‘fs’);

fs.readFile(‘/file.md’, (err, data) => {

  if (err) throw err;

  console.log(data);

});

// moreWork(); will run before console.log

Since fs.readFile () is non-blocking, moreWork () does not have to wait for the file read to complete before being called. This allows for higher throughput.

15. What is Chaining in Nodejs?

Chaining is a system where one stream has an output and that is connected with the output of another stream that creates a chain-like formation of multiple stream operations.

16. Explain the Exit codes in Nodejs? Name some of the exit codes?

As the name is suggesting exit codes are those codes that are used to end the Process where process means a global object that represents a node process.

There are some exit codes given below.

  • Fatal error
  • Uncaught fatal Exception
  • Internal javascript Evaluation failure
  • Non-function internal exception handler
  • Unused
  • Internal exception handler Run-time Failure.

17. What is the working of control flow function?

Control flow function in Nodejs is a code that is implemented between Asynchronous function calls. There are some steps given below which must be followed while implementing it.

  • First, the order of execution must be controlled
  • Second,  collection of the required data is must,
  • Third, concurrency must be limited.
  • When the above process is done the next step of the program is requested.

18. Differentiate between readfile and createReadSTream in Nodejs?

  • Readfile loads complete file that you have marked to read on the other hand createReadStream reads the complete file in the pieces you have declared.
  • CreateReadStream works faster than Readfile. The client will get slower data in the latter one.
  • In Createreadstream, it first read by memory in parts the client will get a part of data that is read and this process will continue until it finishes but in Readfile a file is read by memory completely then the client will get it.

19. How to update a new version of NPM in Nodejs?

For this, you have to give a command for updating in Nodejs

$ sudo npm install npm -g

/usr/bin/npm -> /usr/lib/node_modules/npm/bin/npm-cli.js

npm@2.7.1 /usr/lib/node_modules/npm

20. How to prevent/ fix callback hell?

There are three ways to prevent fix callback hell

Handle every single error

Keep your code shallow

Modularize – split the callbacks into smaller, independent functions that can be called with some parameters then joining them to achieve desired results.

The first level of improving the code above might be:

var logError = function(error){

    if(!error){

      console.log(“success!!”);

    }else{

      console.log(“error”);

    }

  },

  updateTransaction = function(t){

    query(“UPDATE transactions SET value = ” + (t.value*0.1) + ” WHERE id=” + t.id, logError);

  },

  handleTransactions = function(transactions){

    transactions.each(updateTransaction);

  },

  handleClient = function(id){

    query(“SELECT * FROM transactions WHERE clientId=” + id, handleTransactions);

  };

query(“SELECT clientId FROM clients WHERE clientName=’picanteverde’;”,handleClient);

You can also use Promises, Generators and Async functions to fix callback hell.

21. What is the procedure to handle child threads in Nodejs ?

In general, Node.js could be a single-threaded method and doesn’t expose the child threads or thread management ways. however, you’ll still build use of the child threads victimization spawn() for a few specific asynchronous I/O tasks that execute within the background and don’t sometimes execute any JS code or hinder with the most event loop within the application.

22. What are the different timing features of Nodejs?

Node.js gives a Timers module that contains different functions for executing the code after a stipulated period of time. There are some features of different timing that are given below.

setTimeout/clearTimeout –  It is Used to schedule code execution after a specific amount of milliseconds

setInterval/clearInterval – Used to implement a block of code multiple times

setImmediate/clear Immediate – Used to implement code at the end of the current event loop cycle

process.nextTick – Used to schedule a callback function that needs to be requested in the next repetition of the Event Loop.

23. What is the usage of buffer class in Nodejs?

Buffer category in Node.js is employed for storing the raw information similar manner of an array of integers. However, it corresponds to a raw memory allocation that’s settled outside the V8 heap. it’s a worldwide category that’s simply accessible will be accessed in AN application while not importation a buffer module. Buffer category is employed as a result of pure JavaScript isn’t compatible with binary knowledge.

24. What is the role of REPL in Nodejs?

REPL stands for Read, Eval, Print, Loop. The REPL in Node.js is used to implement ad-hoc Javascript statements. The REPL shell allows entry to javascript directly into a shell prompt and evaluates the results. For the purpose of testing, debugging, or experimenting, REPL is very critical.

25. What is libuv in Nodejs

libuv is a Cross-platform I/O abstraction library that supports asynchronous I/O based on event loop. It is written in C and released under MIT Licence.

libuv support Windows IOCP, epoll(4), kqueue(2), and Solaris event ports. Initially, it was designed for Node.js but after that, it is also used by other software projects.

Categories
Backend Developer Database Development Frontend Developers Remote developer

Learn API Inside Out

“An Application Program Interface(API) that provides a developer with programmatic access to a proprietary software application. A software intermidieary that makes it possible for appilication programs to interact with each other and share data.”

What Is An API ?


So API is a communication protocol between the client and the server that simplifies the building of client-side software. It has been described as a “contract” , such that if the client makes a request in a specific format, it will always get a response in a specific format or initiate a defined action.

API can be for a web-based system, operating system, database system, computer hardware, or software library. An API specification can take many forms, sometimes it includes specifications for routines, data structures, object classes, variables, or remote calls. APIs are implemented by function calls that are composed of verbs and nouns. The required syntax is described in the documentation of the application being called. API improves the customer experience as it provides greater functionality and scope of services within a single application or other digital elements.

“An API is a very useful mechanism that allows two pieces of software to exchange data and messages in a standard format. Thus it become an instrument to search for new revenue streams. Open the doors to talent, or automate processes in an innovativeway.”

API: A Data Revolution

  • Effortless Integration
    Allows partners and customers to access your systems in a stable and secure way.
  • Cloud Computing
    APIs are needed for both the initial migration and integration with other systems.
  • Competitive Market
    The market is now so competitive that a company’s success may depend on how usable their API is.
  • Mobile phones
    Devices embedded with sensors fit the service-based structure of APIs perfectly.
  • Flexibility
    APIs allow you to quickly leverage and use your desired services. This lowers risks and allows for greater innovation.
  • Proven Success
    Companies that adopted an API first strategy caused the disruption of entire sectors.

Types Of API: Pick The Right


Software providers may use one of several API types, depending on their preferences and the functionality they are offering. As its good to know all about the path you choose here are the possible integration and development between different software platforms.

REST


REST, or Representational State Transfer, is a most common API category that is not dependent on a specific protocol. It offers a flexible integration option that makes developers able to achieve their goals by using a standardized set of processes to achieve their goals. It provides a straightforward architectural style and streamlines the connection between the client and the server. REST is considered a relatively user-friendly API to work with, and many developers are experienced in this technology.

SOAP


SOAP, or Simple Object Access Protocol, is an API that connects different platforms together through HTML and XML. The structure and requirements for SOAP are more rigid than REST, and it’s defined by a specific protocol. Web applications have started moving away from this older traditional type. It is hard to implement flexible integration here. However, this structure does allow for more stringent security measures and includes stateful operations without custom coding.

ASP.NET


ASP.NET is a specific form of a REST API .NET technology. The main benefit of using this type is the structured framework that’s in place. If you are working with windows-based technology, you can send HTTP protocol messages to a variety of platforms. Dot NET framework is lightweight and easy to work with, which can speed up development time and add flexibility to your third party integration.

API Lifecycle: 4 Stages


API’s lifecycle basically summarizes the whole lifespan, right from initial conception, to deprecation and final retirement. APIs’ lifecycle varies with its core functionality and the nature of software or business. Let’s analyze the four stages of the API lifecycle.

API Panning, Design, Analysis


This stage is generally called the API Requirement Definition stage. In this stage, providers need to determine a definition in which they have to give the reason for creating a new API, the objective that it will achieve, and the overall business strategy that will be implemented. It has to be analyzed whether creating an API would indeed solve the existing requirements. And after its establishment, the purposes of the API are to evolve with the overall organizational objectives.

At this stage some points have to be decided:-
1) API growth model
2) Projection/Predictions of usage
3) Mission statement(s)
4) Expected returns from the API
5) API marketing and promotional methods to be adopted.

Once these have been decided another extremely important element is, finalizing the type of API to create.
1) Public APIs
2) Private APIs
3) Partner APIs

API Development And Integration


API providers must understand the exact technical requirements and capabilities of the program interface. The API hosting tools and management methodology, an understanding of the protocols to be used is important. Developers need to be aware of all the operations as well, the security features, access control options and the quality of end-user-experience the API will provide. The scalability and the size of APIs are also the points to considerate.

There are many API development frameworks, depending on the programming language used by developers. Here are a few of them:-

a) Sinatra and Grape (for Ruby)
b) REST.li and JAX-RS (for Java)
c) Slim (for PHP)
d) Restify and Express.js (for Node.js)
e) Django and Flask Web (for Python)

Note: AppNow is also an often-used tool for API prototyping, data model specification and deployment, and demonstrations. Deployment with AppNow (with CRUD RESTful API and AngularJS) can be tested with the Swagger tool.


Versioning is one of the most important parts of this stage. Versioning is important to keep things systematic.
It included:-
i) API designing (ensuring both human-usability as well as machine-readability)
ii) API construction
iii) API security (through access control tools)
iv) API testing

The rate limit is a common security strategy for APIs. These put an upper limit on the total number of network requests within a time period. As API lifecycle is iterative, it is easy to go back to the Analysis stage at any time and make changes, as and when required.

API Operations and Management


By the end of Stage 2, a two-way connection between the API backend and corresponding website or mobile app has been established. In this stage, an intermediate layer- API management is created and inserted between the two, to boost API intelligence and performance levels.

Systematic API management helps in:-
a) Making the user-behavior more predictable.
b) Monitoring key API analytics to increase performance.
c) Establishing API monetization scheme.
d) Securing the API endpoints.

One of the biggest inclusion in the third stage of the lifecycle is API testing and bug fixing. This makes the interfaces smoother and glitch-free. Initial user-opinions and feedback also need to be collected and analyzed.

Note: API documentation, initiated in the previous stage, has to be regularly updated and maintained during the Operations stage. All the changes made in the structure of the API should be recorded in the documentation / changelog / release notes.


In API Management layer, developers have to work with 2 separate URLs:

a) The first URL exists between the application/website (final product) and the management tab. It is published and is viewable to everyone who has authorized access to the interface.
b) The second URL exists between the management tab and the API. This one remains private and is not accessible to any third-party entity.

There are some features and solutions that any standard API management platform should offer. These include the API contracts, the security, and access controls, the documentation, developer portal access, analytics and usage, and of course, all billing-related information.

API Engagement, Adoption, and Retirement


There are 2 major components in any campaign to drive up the engagement/ adoption rates of an API:
1) Boosting its discoverability and usability. Users should be able to find the API easily, and not run into any problem while working with the software.
2) Creating interesting use-cases to highlight the utility of the API to app/web developers. Delivering top-notch developer-experience(DX) is always of the essence.

API developer program typically has the following:

a) Developer portal (the main point of the entrance within the API)
b) API Evangelists (for online and offline promotion of APIs)
c) Pilot partners (for collecting feedback and suggestions)
d) Outreach acceleration with partners (for increasing the reach of API-related messages, with the help of partner organizations)
e) Community development (for selecting the right web and social media channels to promote APIs)

Note: Creating a scheme to monitor the effectiveness of marketing campaigns should also be a part of an exhaustive API Developer Program. All partners should be leveraged properly, to maximize the outreach of the API in existing markets.


Retiring an API is pretty much like discontinuing any piece of software. It happens when the usage metrics start to go down steadily, there is little or no innovation on the part of app developers, and/or a mismatch of revenue-related objectives. 

API design: Does It Matter?


Building APIs is hard and should be very careful with your APIs. An API can be your best asset but also your biggest liability. A bad user experience while consuming your APIs will lead you to endless support calls and a bad reputation as well. This all could make your service unreliable. So it’s important to plan before implementing your API. This is where you design and apply RESTful API description formats like the OpenAPI Specifications and API Blueprint.

  • Defining API design
    API design involves a lot more than the way you write normal code. Designing an API means providing an effective interface that helps your API’s consumers better understand, use and integrate with them while helping you maintain it effectively. API design should have:-
    a) The structure of resources
    b) The documentation of resources

  • Helps in Better implementation
    An API’s design is a blueprint on what your API wants to achieve and gives a brief overview of all the endpoints and CRUD operations associated with each of them. An effective API design can greatly help in implementation and prevent complicated configurations.

  • Incremental development
    API development is a continuous process. As your products and services evolve, so should your API. Having a clear design helps your organization and team know exactly which resource, or sub-resources, would need to be updated and preventing confusion. A well-designed API can prevent repeating work and help developers know exactly which resources would need to be updated and which ones should be retired. 

  • Better Documentation
    Documentation is crucial for building the interface that lets your API be consumed. In many cases, comprehensive documentation is done only after the API’s resources and response-request cycles are mapped out. A solid initial structure makes documenting the API faster and less error-prone.

  • Improves Developer Experience
    A good API design makes the life of the end developer easy. It’s quick to understand with all the resources well organized, fun to interact with and easy to look, so the people who consume your API have a smooth experience working with it.

How An API Works


How are APIs work in the real world?  Let’s look at this example of booking a flight.

When you search for flights online, you have a menu of options to choose from. You choose a departure city and date, a return city and date, cabin class, and other variables like your meal, your seat, or baggage requests.

To book your flight, you need to interact with the airline’s website to access the airline’s database to see if any seats are available on those dates, and what the cost might be based on the date, flight time, route popularity, etc.

You need access to that information from the airline’s database, whether you’re interacting with it from the website or an online travel service that fetches information from multiple airlines. Alternatively, you might be accessing the information from a mobile phone. In any case, you need to get the information, and so the application must interact with the airline’s API, giving it access to the airline’s data.

The API is the interface that, runs and delivers the data from the application you’re using to the airline’s systems over the Internet. It also then takes the airline’s response to your request and delivers right back to the travel application you’re using. Moreover, through each step of the process, it facilitates the interaction between the application and the airline’s systems – from seat selection to payment and booking.

APIs do the same for all interactions between applications, data, and devices. They allow the transmission of data from the system to the system, creating connectivity. APIs provide a standard way of accessing any application data, or device, whether it’s accessing cloud applications like Salesforce, or shopping from your mobile phone.

Most Popular APIs

  • Google Maps API:- Developers embed Google Maps on webpages using a JavaScript or Flash interface. Google Maps API is designed to work on mobile devices and desktop browsers.

  • YouTube APIs:- Google’s APIs let developers integrate YouTube videos and functionality into websites or applications. YouTube APIs include the YouTube Analytics API, YouTube Data API, YouTube Live Streaming API, YouTube Player APIs, and others.

  • Flicker API:- The Flicker API is used by developers to access the Flick photo sharing community data. The Flickr API consists of a set of callable methods and some API endpoints.

  • Twitter APIs:- Twitter offers two APIs. The REST API allows developers to access core Twitter data and the Search API provides methods for developers to interact with Twitter Search and trends data.

  • Amazon Product Advertising API:- Amazon’s Product Advertising API gives developers access to Amazon’s product selection and discovery functionality to advertise Amazon products to monetize a website.
Categories
Business Database Development Startup Top Coder

Five Upcoming Tools For Software Developers, you should keep your eye on.

You will definitely agree that today developing tools are the helping hands of the developers. There are too many tools that help to create robust applications. A developer should know about the upcoming tools that might be helpful to them for future projects.

Here are the top five upcoming tools for software developers that fulfill their need to build projects.

1. Creates a direct workflow for your software:

GitHub Actions


It is the first new upcoming developer’s tool and you can try GitHub Action by signing up on its official website. It gives developers the flexibility to build an automated lifecycle workflow for software development. And Workflows run in Linux, macOS, Windows, and containers on GitHub-hosted servers. So developers can create workflows using actions defined in their repository, open-source actions in a public repository on GitHub, or a published Docker container image.


Some feature of GitHub Actions are:

Write tasks (Actions) to create your custom workflow.

  • GitHub introduced GitHub Actions to customize your workflow. “Actions” is a feature of GitHub using code packaged in a Docker container running on GitHub’s servers. Developers can set up triggers for events, such as introducing new code to a testing channel, that set off Actions to take further steps involving that code defined by principles set by administrators.
  • Like most of the projects, software development is usually broken down in dozens, hundreds, or thousands of small steps depending on the scope of the project. Teams need to coordinate on the progress of those steps, such as whether they are ready for review or still need some work, as well as coordinating the merging of that code into existing software without breaking anything.

These Actions, which is now

  • In limited unrestricted beta,
  • Developers can set up the workflow to build,
  • Use packages, and
  • Update and deploy the code.

Compile and Run automatical

  • This tool is considered as a “Biggest shift ever in the history of GitHub”. Neither, have you ever thought that there would a tool that customizes your workflow according to your needs? It’s just a new concept to enhance the productivity of the developers. It is a more flexible version of shortcut, on GitHub as well as it designed to allow developers to create an action inside a container to augment and connect their workflow.

Actions are shareable and discoverable

  • That means no more mucking around different services just to create one single project or get your code into production. With GitHub Actions, you can continuous integration tool that allows developers to automate tasks for their web projects which consume less time by sharing and discover the codes.
  • Just like Repos in GitHub- To put your projects up on GitHub, it is important to create a repository for it to live in. You have to create public repositories for an open-source project and this includes a license file that determines how many people you want to share your codes. But with Actions, it is easy to share and discover the codes. GitHub Actions now supports CI/CD, free for public repositories.
  • It allows the developers who have worked on GitHub projects in private repositories. That accounts contain a huge amount of corporate or business development projects. To list contributions to some of those projects without giving away all the secrets.

Some cool terms use by developers on GitHub Action:

  • Workflow
  • Workflow File
  • Job
  • Workflow Run
  • Action
  • Step
  • Continuous Integration (CI)
  • Continuous Deployment (CD)
  • Artifact
  • Events
  • Runner
  • Virtual Environment

Let’s move to the second another Tool for developers.

2. A transparent development automation tool:

DeployPlace


Automate deployments with your custom-ready CI even for complex apps, to your servers or cloud. It is a transparent deployment tool by developers for developers, with the possibility to easily deploy complex applications, as well as static websites or client-side projects directly from your CI.

It is a software deployment tool that lets you deploy your applications, regardless of the level of complexity. This deployment product supports the deployment of Kotlin, Java, Scala applications, and does an excellent job of providing a live editor. With the editor, you can monitor and control every step involved in the software deployment process.

As a DevOps or Site Reliability Engineer, you’d find what DeployPlace offers to be quite exciting. The deployment tool is very supportive of CI/CD.

DeployPlace will amaze you with its focused features which positively hit the market.

  • Control your program with live editor
    It is absolutely transparent, unlike other deployment tools, DeployPlace is one step up. It comes with live editor which controls all your actions and makes things easy for you.

  • Get an advanced Dashboard for your applications
    This another feature that creates the history say deployPlace committed to auto-deploy and comes with external integrations such as Slack notifications, New Relic, Sentry, etc.

  • Working on any complex application- make it easy with DelpoyPlace
    The developers with DeployPlace easily deal with complex application. Just prepared your CI and it will do all for you. Customizable deployment templates allow you to tweak any sensitive parameter to ensure every aspect of your server is set up properly.

DeployPlace will useful for developers who do not want to get involved in the deployment process of apps. So you can center on writing code and developing features, with the support that it’ll be deployed with the highest standards when using DeployPlace. DevOps Developers looking to abstract complexities when deploying services will also find DeployPlace to be a great tool.

You only need to add the CI of your app and the server details and the job is done. CIs such as GitlabCI, CircleCI, TravisCI, BambooCI, and Jenkins are all supported.

This one is really cool for the developers, New as well as easy. Let’s move to the next tool that is:

3. As easy As Pie-

QueryPie


QueryPie welcomes the developers with a complete cross-platform database IDE. Mark the month of July 2019, the Beta version of QueryPie was officially released for the developers who want to experience a new way to work with data. Using it is easy as well as pleasing for the UI/UX.

The beta version of QueryPie supports the OS environment for Windows, Mac, and Linux. And currently, it supporting DBMSs- MySQL, MariaDB, and AWS Aurora for MySQL. The Beta version of QueryPie is available currently.


It will provide you some awesome feature that makes your developing experience so rocking.

  • Directly edit in the data grid
    You can add, delete, and copy data easily right in the data grid.

  • Run import/ export and get the result export list
    The top icon provides a simple import/export function. Just click the bottom Export Files icon to see a list of downloaded files.

  • Have SQL AutoComplete
    Fast, automatic table/column/view information and query completion enhances database productivity and makes writing SQL easier

  • Auto-Commit Option setting and Code Review Capabilities
    Auto-Commit mode is simple to turn on or off. View a list of uncommitted transactions by clicking on the corresponding button at the top to enable code review.

  • Easily get SQL history and syntax
    When you click the right SQL History button, you can view the history of queries that runs. Simply press the Copy button to copy and re-run or share the syntax.

  • Run multiple SQL queries
    Run multiple queries at the same time and view all the results instantly without having to switch between panels. You can view the Run result panels side-by-side or stacked, making comparisons more convenient

  • Convenient object information panel and search function
    You can compare several table information using panels and view Data, Structure, Index, Relation, Trigger, Info and Scripts in the table. You can also use the search function to find and filter only the specific data you want to view.

  • Select or retrieve database
    When you connect to the database, you can select the schema in the upper left corner and see a list of tables, views, procedures, triggers and more. You can also search directly for these elements. Merely double-click a table name to view table information in the right-hand object panel.

  • Get a Dashboard connection list
    You can easily enter and create connection information from the main dashboard. Linked databases are sorted by color which makes finding and accessing specific databases very easy.

QueryPie targetS to Database users from different backgrounds: DBAs, developers, and SQL Engineers to Planners related directly to the databases, Marketers, and Data Scientists.

It’s essential for all startups and small businesses that work with databases. Development organizations can configure and manage databases and run SQL faster than any other tool using QueryPie. Non-development organizations can securely access databases, analyze and visualize data they want, and organize as well as share dashboards with QueryPie.

Additionally, all actions passed to the database through QueryPie are transparently written in a blockchain. This enables high-level database security audits, and also provides a database Fraud Detection System (FDS) that lets users learn the usual database access patterns. Users can also track SQL execution patterns and send alerts to the administrator in advance if abnormal activity is detected. With this method, companies can easily meet the legal guidelines for various expected privacy measures.

This one the sweet like a Pie and familiar to MySQL.

4. AutomatedApi– For backend services to automate


AutomatedApi is up and running with user registration, login, API creation, and API access. The main purpose of this tool is to store data for your applications for further use so that you can easily able to get any data without worrying about how it works.

Reserve your user name now with Automated Api. It provides you three simple #steps to build applications.

#First Just tell Automated API, what you want to store and click

After that, #Secondly click and reach the familiar reference interface to work and connect to your service.

#Third Chill and have a break it’s done!

So, have you see in a few simple steps you save your lots of time. AutomatedApi lets you hit the ground running, so you can deliver new functionality faster. Stop spending time on code stuff and start spending it on developing. It generates solutions in minutes that would take developers hours. From basic models to complex object graphs, the more you build the more you save.

Client-side applications are everywhere, and many client-side developers do not enjoy doing server-side tasks. However, client-side applications still need to display data, and it has to come from a server. With AutomatedApi, frontend developers can build their applications and consume APIs without needing to have the skills of a backend developer. Simply as setup and consume. Automated API is currently in its Closed Beta stage.

5. Expand your code Brain- ExBrain

Writing code is hard. Reading code is even harder!

ExBrain is a tool which is uses as the external brain of developers. It will help the developers to break down the workload by learning silly codes and prioritize and focus on what is important to learn to get maximum results.

Because the developers spend most of their time to learning or reading code and get frustrated with this task, so to ease their work this tool coming in the market. Each codebase has its own format. Understanding what the classes, functions, and methods better. It is more useful to the developers who are new in this coding field.


This external brain works so perfectly. Well! its feature proves it.

  • Follows the progress
    This tool follows your work progress while learning code. ExBrain shows how progressively you completing your work.

  • Divide and generate
    ExBrain generates the code by dividing codebase into manageable blocks, which is quite easy for the developer to learn the code and split the codebase into flashcards

  • Never forget what learned
    ExBrain helps the developer to remember everything that they learned by using the proven technique of spaced repetition.

ExBrain will improve your productivity by helping you learn and remember everything about your codebase.

Wrap-Up


A lot of software development tools look to provide solutions to problems faced when creating software. There are many products in the market but these tools actually help the developers to make large and customize applications. But these are the five tools for developers, which work as their helping-hands, as well as increase their productivity that they have more time to build applications.

Categories
Backend Developer Business Cloud Database Development

Top 20 docker interview questions for 2019

Docker– A well-known technology widely used and appreciated by DevOps engineers originated in 2013 and it turned out to be a big hit by the end of 2017. So what makes Docker so darn popular? The following statement about Docker will definitely give you an overview of it.

“Docker is hotter than hot because it makes it possible to get far more apps running on the same old servers and it also makes it very easy to package and ship programs.”

All the noise about Docker is happening because companies are adopting it at a remarkable rate. Numerous businesses that had already moved their server application from virtual machines to containers. As Docker is a new trend in tech town no doubt its engineers are also in demand.


Here are the Top 20 Docker interviews question that will help you to achieve your goal:-

1. What is Docker?


Docker is a set-of-platform as service products. It’s an open-source lightweight containerization technology. It has made a popular name in the world of the cloud and application packaging. Docker allows you to automate the deployment of applications in lightweight and portable containers.

2. Difference between virtualization and containerization?


Containers provide an isolated environment for running the application. The entire user space is explicitly dedicated to the application. Any changes made inside the container is never reflected on the host or even other containers running on the same host. Containers are an abstraction of the application layer. Each container is a different application.

In virtualization, hypervisors provide an entire virtual machine to the guest including Kernal. Virtual machines are an abstraction of the hardware layer. Each VM is a physical machine.

3. What is a Docker Container and its advantages?


Docker containers include the application and all of its dependencies. It shares the kernel with other containers, running as isolated processes in user space on the host operating system. Docker containers don’t need any specific infrastructure, they run on any infrastructure, and in any cloud. Docker containers are basically runtime instances of Docker images.
Here are some major advantage of using Docker Container:-

  • It offers an efficient and easy initial set up.
  • It allows you to describe your application lifecycle in detail.
  • Simple configuration and interacts with Docker Compose.
  • Documentation provides every bit of information.

4. What are Docker images?


Docker image is the source of the Docker container Or can say Docker images are used to create containers. When a user runs a Docker image, an instance of a container is created. These docker images can be deployed to any Docker environment.

5. Explain Docker Architecture?


Docker Architecture consists of a Docker Engine which is a client-server application:-

  • A server which is a type of long-running program called a daemon process ( the docker command ).
  • A REST API that specifies interfaces that programs can use to talk the daemon and instruct it what to do.
  • A command-line interface (CLI) client (the docker command).
  • The CLI uses the Docker REST API to control or interact with Docker daemon applications use the underlying API and CLI.

6. What is Docker Hub?


Docker hub is a cloud-based registry that helps you to link code repositories. It allows you to build, test, store your image in the Docker cloud. You can also deploy the image to your host with the help of the Docker hub.

7. What are the important features of Docker?


Here are the essential features of Docker:-

  • Easy Modeling
  • version Control
  • Placement/Affinity
  • Application Agility
  • Developer Productivity
  • Operational Efficiencies

8. What are the main drawbacks of Docker?


Some of the disadvantages of Docker that you should keep in mind are:-

  • It doesn’t provide a storage option.
  • Offer a poor monitoring option.
  • No automatic rescheduling of inactive Nodes.
  • Complicated automatic horizontal scaling set up.

9. Tell us something about Docker Compose.


Docker Compose is a YAML file that contains details about the service, network, and volumes for setting up the Docker application. So, you can use Docker compose to create separate containers, host them and get them to communicate with other containers.

10. What is Docker Swarm?


Docker Swarm is native clustering for Docker. It turns a pool of Docker hosts into a single, virtual Docker host. Docker Swarm serves the standard Docker API, any tool that already communicates with a Docker daemon can use Swarm to transparently scale to multiple hosts.

11. What is Docker Engine?


Docker daemon or Docker engine represents the server. The docker daemon and the clients should be run on the same or remote host, which can communicate through command-line client binary and full RESTful API.

12. Explain Registries


Two types of registry are –

  • Public Registry
  • Private Registry

Docker’s public registry is called Docker hub, which allows you to store images privately. In Docker hub, you can store millions of images.

13. What command should you run to see all running container in Docker?


$ docker ps

14. Write the command to stop the Docker Container.


$ sudo docker stop container name

15. What is the command to run the image as a container?


$ sudo docker run -i -t alpine /bin/bash

16. Explain Docker object labels.


Docker object labels is a method for applying metadata to docker objects including images, containers, volumes, network, swarm nodes, and services.

17. Write a Docker file to create and copy a directory and built it using python modules?

FROM pyhton:2.7-slim

WORKDIR /app

COPY . /app

docker build –tag

18. Where the docker volumes are stored?


you need to navigate


/var/lib/docker/volumes

19. List out some important advanced docker commands.

20. How do you run multiple copies of Compose file on the same host?


Compose uses the project name which allows you to create unique identifiers for all of a project’s containers and other resources. To run multiple copies of a project, set a custom project name using the -a command-line option or using COMPOSE_PROJECT_NAME environment variable.

Categories
Backend Developer Business Cloud Database Development

Top 10 DevOps Automation Tools

“Automation does not need to be our enemy. I think machines can make life easier for men, if men do not let the machines dominate them.”

~ John F. Kennedy

In today’s digital age Automation tools work as the savior for engineers. Everyone is either creating automation tools or getting automated. Using automated tools is one of the best ways to save time, improve quality and flexibility, enhance productivity. These tools help you to identify security threats and breaks in runtime and prevent you from wasting time in restructuring.

According to market research by a well-known organization around 35% of the organizations are already using automation tools for their testing procedures and 29% have plans to implement automated strategies and tools for their products.

“The first rule of any technology used in a business is that automation applied to an efficient operation will magnify the efficiency. The second is that automation applied to an inefficient operation will magnify the inefficiency.”

~ Bill Gates

Automation plays a inseparable role in the DevOps from code generation, Integration, delivery to continuously testing and monitoring. In DevOps, operational teams started using automation for all their work that give DevOps the wings to fly so high. In a typical DevOps, a code is generated on the developer’s machine then it produces some output as a result and that result is being monitored throughout. Automation gives this process a kick for triggering the build, running unit test cases.

“I think one of the most interesting things about automation isn’t on the practical side. I think it’s about creating magic and wonder and moments of splendor.”

~ Genevieve Bell


Automation is also empowering other basic code quality, coverage test cases, and security-related test cases. Automation test cases are not limited to just unit test its included installation tests, UI tests, user experience tests, etc. DevOps makeable the operations team to implement automation in all their activities from provisioning the servers, configuring the servers, configuring the networks, configuring firewalls to monitoring the application in the production system.

Now you must be wondering how you can use automation for DevOps. To help you in this here are the top 10 DevOps automation tools.

1- Gradle

  • Gradle has been counted in the top 20 open-source projects and is trusted by millions of developers.
  • Build anything here either you write code in Java, C++, Python or any other language of your choice.
  • Here package is available for deployment on any platform.
  • Go monorepo or multi-repo.
  • One of the most versatile DevOps tools.
  • Gradle provides a rich API and a mature ecosystem of plugins and integration.
  • Model, integrate and systematize the delivery of your software from end to end.
  • Scale-out development with elegant and deliver faster.
  • Handles from compile avoidance to advanced caching and beyond, Gradle pursues performance relentlessly.

2- Git

  • This DevOps tool was designed by Torvald while maintaining a large distributed development project.
  • Git is one of the most popular distributed SCM (source code management) tools.
  • It is compatible with existent systems and protocols.
  • This tool is widely used and appreciated by remote teams and open source contributors.
  • By using Git you can track the progress of your development work.
  • Here you can save various versions of your source code and use these versions according to your needs.
  • You can create separate branches and merge new features at the time of launch. Hence this tool is also great for experimenting.
  • Git strongly supports nonlinear and distributed development of large projects.
  • It automatically accumulates garbage when enough useless objects have been created.
  • Git stores newly created files in a network byte stream called ‘packfile’.

3- Jenkins

  • Jenkins is a self-contained Java-based program.
  • It contains packages for Windows, Mac OS X, and other Unix-like operating systems.
  • Jenkins can be used as a simple CI server as well as a continuous delivery hub for any project.
  • Jenkins can be easily set up and configured by its web interface.
  • That includes on-the-fly error checks and built-in help.
  • Jenkins integrates with practically every tool in the continuous integration and continuous delivery toolchain.
  • Jenkins can be extended via its plugin architecture.
  • This tool makes you able to distribute work across multiple machines, helping drive builds, tests, and deployments across multiple platforms.

4- Docker

  • Docker is a set-of-platform as service products.
  • It uses OS-level virtualization to deliver software in packages called containers.
  • Makes you able to run and share container-based applications from the developer’s machine to the cloud.
  • It is based on Docker core building blocks including Docker Desktop, Docker Hub, and Docker engine.
  • Docker hub is the world’s largest container image library.
  • It scales up to 1K nodes.
  • Update the app and infrastructure with zero downtime.
  • Developers can quickly ramp productivity and deliver apps to production faster.

5- SeleniumHQ

  • Selenium is a browser automation tool. It is for automating web applications for testing purposes.
  • It is supported by some of the largest browsers vendors that make selenium a native/ part of their browser.
  • It also plays a vital role in countless other browser automation tools, API and frameworks.
  • Selenium WebDriver- “A collection of language-specific bindings to drive a browser- the way it is meant to be driven”.
  • Selenium used for creating robust, browser-based regression automation suites and tests.
  • Its scale and distribute scripts across many environments.
  • Selenium IDE- “a Chrome and Firefox add-on that will do simple record and payback of interactions with the browser“.
  • It creates quick bug reproduction scripts.

6- CHEF

  • Chef is one of the founders of the DevOps movement.
  • Chef work with thousand of the innovative companies around the world.
  • It delivers its vision of digital transformation by providing practices and platforms to deliver software at speed.
  • Chef provides tested hardened software distributions.
  • Chef maintains security and stability with patches and bug fixes for the life of the product.
  • It provides an easy and quick way to get organized content to your Enterprise Automation Stack.
  • With its clock feature, you can keep things running on time.

7- Ansible

  • Ansible is an extremely simple IT automation engine.
  • It automates cloud provisioning, configuration management, application deployment, intra-service orchestration, and many other IT needs.
  • Ansible designed for multi-tier deployments since day one,
  • This tool doesn’t use agents and additional custom security infrastructure, so it’s easy to Deploy.
  • It YAML in the form of Ansible Playbooks.
  • Ansible works by connecting to your nodes and pushing out Ansible modules to them.
  • Ansible then executes these modules and removes them when finished.
  • There are no servers or databases required, your library of modules can reside on any machine.

8- Nagios

  • Nagios is a well-known server monitoring software on the market.
  • The flexibility, it provides to your servers with both agent-based and agentless, make it best fit in the zone.
  • There are over 5K different add-ons available to monitor your servers.
  • Their effective monitoring service allows your organization to quickly detect application, service, or process problems.
  • Nagios provides tools for monitoring of applications and application state including-
    -Windows Applications
    -Linux Applications
    -Unix Applications
    -Web Applications
  • Nagios XI provides monitoring of critical infrastructure components including applications, services, operating systems, network protocols, systems metrics, and network infrastructure.
  • Nagios Log Server simplifies the process of searching your log data. It notifies you when threats arise.

9- ELK

  • ELK is the acronym for three open-source projects: Elasticsearch, Logstash, and Kibana.
  • Elasticsearch is a search and analytics engine.
  • Logstash is a server-side data processing pipeline that ingests data from multiple sources simultaneously, transforms it, and then sends it to a “stash”.
  • Kibana lets users visualize data with charts and graphs in Elasticsearch.
  • The Elastic Stack is the next evolution of the ELK Stack.
  • It is an open-source, distributed, RESTful, JSON-based search engine.
  • Popular among users because of its scalability and flexibility.
  • Whether to analyze security events or freely slice and dice metrics, the worldwide community kept pushing boundaries with ELK.

10- Splunk

  • Splunk brings data to every question, decision, and action.
  • Accelerate innovation by acting fast.
  • It helps you solve problems with a platform built for real-time data.
  • Splunk amplifies your data’s impact.
  • It makes data accessible and valuable to IT, security and more.
  • It grows with your needs without compromising performance from gigs to petabytes.

“Devops is not a goal, but a never-ending process of continual improvement.”

–  Jez Humble


Categories
Business Database Development Startup

How Blockchain Is Revolutionizing The Supply Chain Industry?

The Supply chain has transformed, companies have not updated the underlying technology for managing them in decades. With Blockchain technology, companies can rebuild their approach to supply chain management at the ecosystem level and go from the island of insight to an integrated global view.

“At its most basic level, the core logic of blockchains means that no piece of inventory can exist in the same place twice.”

-Paul Brody
EY Global Innovation Blockchain Leader

Everyone loves to hate middleman, but it turns out they are really useful. Until the advent of Bitcoin and blockchain technology, the only way you could get a large number of entities to agree upon a shared, truthful set of data, such as who owns how much money, was to appoint an impartial intermediary to process and account for all transactions. Blockchain makes it possible for ecosystems of business partners to share and agree upon key pieces of information. Facebook’s Libra is also using blockchain technology.

Instead of having a central intermediary, blockchains synchronize all data and transactions across the network and each participant verifies the work and calculations of others. This enormous amount of redundancy and crosschecking is why financial solutions like Bitcoin are so secure and reliable, even as they synchronize hundreds of thousands of transactions across thousands of network nodes every week.


“The Core logic of blockchain applied to the supply chain”


Apply that same security and redundancy to something like inventory, and substitute supply chain partners for banking nodes, and you have the foundation for a radically new approach to supply chain partners for banking nodes, and you have the foundation for a radically new approach to supply chain management.
The use cases for this new way of working are compelling. At its most basic level, the core logic of blockchain means that no piece of inventory can exist in the same place twice. Move a product from finished goods to in-transit, and that transaction status will be updated for everyone, everywhere, within minutes, with full traceability back to the point of origin. Before diving into the pool of ” How Blockchain is Revolutionizing the Supply Chain Industry” let’s take a brief of what actually Supply Chain and Blockchain are:-

Blockchain


Most have heard the phrase ” Blockchain is the greatest invention since the Internet ” or ” Everything will be Blockchain in a few years “. These phrases tend to leave people more confused then they were previously. Blockchain can be understood as a decentralized, distributed database that very securely holds digital records. Furthermore, although all records are transparent and accessible to the public, they are not to be altered deleted or edited. All data inserted into the blockchain remains impaired permanently. Each transaction or record inserted in the Blockchain registers a different “Block” on the chain.

Basically, Blockchain provides a method of record-keeping which is highly secure and more efficient for businesses/individuals to work with.

Supply Chain Management (SCM)


Nowadays we have the luxury of having ready-made, high-quality products right on our doorstep. It’s easy to go to a store, buy a shirt, and not think of where that shirt came from or how it was manufactured. For that shirt or shirt came from or how it was manufactured. For that shirt or product to make it store shelves it must go through plenty of hands stemming all the way from the provider of the raw materials, to the retailer who is giving you the ready-made product. The process which links all the parties involved in delivering you the ready-made product is called the Supply Chain.

Logistic is a huge aspect within Supply Chain Management, as products are shipped, stored in warehouses, go through customs, etc. The entire process is time consuming, costly, and many times complicated. In addition, since global trade involves dealing with foreign organizations, importers and exporters may have to deal with political outcomes, international law, and high tariffs.

“Through blockchains, companies gain a real-time digital ledger of transactions and movements for all participants in their supply chain network. But don’t let the simplicity of the tool overshadow how transformational it is.”

Paul Brody
EY Global Innovation Blockchain Leader

Blockchain Stepping In


Some of the most urgent issues facing supply chains can be addressed through blockchain technology, as it provides novel ways to record, transmit, and share data.

In essence, a blockchain is a unique database system created and maintained by participants in a decentralized network. It offers a secure and reliable architecture for conveying information and transactions ( e.g. the exchange of data and assets among participants in a supply chain), which can be recorded digitally. As the distributed ledger is decentralized, each stakeholder maintains a copy, which prevents a single point of failure or data loss. This also means blockchains are highly resistant to altering or tampering. Such accurate and tamper-proof records secure data integrity and can be accessed to make regulatory compliance easier. Ultimately, blockchain can increase the efficiency and transparency of supply chains and positively impact everything from warehousing to delivery to payment.

Through the implementation of Blockchain technology in the Supply Chain Industry, products can be tracked and traced throughout their entire process. All parties involved from beginning to end in the supply chain will be aware as the product is transacted and handled from party to party at all times.


Traceable and Immutable Records


Blockchain data is immutable and digital signatures are required to confirm information ownership. If multiple companies work together they can use a blockchain system to record data about the location and ownership of their materials and products. This data is stored in the blockchain, which offers a full history of all items in the supply chain. Any member of the supply chain can see what is going on as materials move from company to company. These data records cannot be altered and are highly Traceable. In the event of a defective product, the source of the problem can be identified more quickly, which improves the efficiency of product recalls and disruption resolution between stakeholders in the chain.


Having a transparent and complete inventory of product flow help businesses make better decisions. It gives stakeholders and customers more confidence in the products’ quality. The improved transparency is also a tool for fighting fraud and counterfeiting.

Cost Saving


There is a lot of waste created because of the inefficiencies of supply chains. This is especially prevalent in industries that have perishable goods, such as the food industry. The improved tracking and data transparency that blockchain offers can help the business identify these wasteful inefficiencies so they can implement targeted cost-saving measures.


The use of blockchain can also eliminate fees associated with funds passing into and out of various bank accounts and payment processors. Such fees cut into profit margins, so being able to take them out of the equation is significant.

Interoperability


One of the problems with current supply chain technology is not being able to integrate data across every partner in the process. In contrast, blockchains are built as distributed systems that maintain a unique and transparent data repository. Each party in the network contributes to adding new data and verifying its integrity. This means that all parties involved in the network, so one company can easily verify the information being broadcasted by another.

Replacing Electronic Data Interchange Systems


Many companies rely on Electronic Data Interchange (EDI) systems to send information to each other. However, this data goes out in timed batches rather than in real-time. Thus, if a shipment goes missing or pricing changes, other participants in the supply chain will only get this information is updated in real-time and quickly distributed to all parties involved.

Transparency


The blockchain is a shared database that ensures honest transparency. All partners have the responsibility to upload their information and data about the product. A digital collection of accurate data improves accountability and trust between partners. Blockchain technology can show updates to the product in mere minutes. Everyone involved knows exactly where a product stands at all times. You can see exactly where a product is, how it’s being made, and when it will be delivered all in one place.

Streamlined


All of the logging involved with the blockchain is done digitally. This leads to less administrative work and more consistent and speedy data tracking. With the blockchain, you cut out the middleman and sign on to the blockchain to instantly download information. Everything is in one spot, making communication and operations highly streamlined. The blockchain is global and scalable. The technology can support worldwide partnerships and communications just as fast as regional partnerships. This makes it the ideal solution for an economy of globalization.

Enhanced Analytics


The blockchain offers complex solutions to analyze the data being uploaded. It can help create forecasts and predictions based on previous data, and it can allow users to pinpoint legs in the supply chain. These data analytics are proving invaluable to companies who want to minimize supply chain expenditures and grow their businesses.

Customer Satisfaction

The blockchain technology can also be used to boost customer satisfaction. Business owners can use the blockchain database to see where items are in production and shipment to build a delivery timeline for their customers. It also has a social advantage. A clothing brand with a dedication to fighting sweatshops may give their customers access to the blockchain, showing them a social consciousness approval form, and a labor union sheet.

A World of Potential!!!!!
The Wall Street Journal recently posted an article that exclaimed, “after initial tests, 12 of the world’s biggest companies, including Walmart and Nestle, are building a blockchain to remake how the industry tracks food worldwide.”


The blockchain is already revolutionizing the financial world, and it’s only a matter of time until it takes over every other industry.

A technology like this is a generational technology, something that will change the way the world works. For something like the supply chain, the blockchain technology will update a 200-year-old system and make it more reliable, secure, and transparent.