Skip to content

A commnad line interface app, which can add , update, delete or other operations can do. Basically this app help the users can write queries into terminal for work with database in CLI.

Notifications You must be signed in to change notification settings

Nik4Furi/customer_cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

customer_cli

A CLI(command line interface) app

customer_cli, basically is a command line app, can help to add,update,delete or other operations can do at the terminal or command bases.It can use to CRUD operations do ,at writing queries on terminal.

Indexing the contents

Badges

GitHub Repo stars GitHub watchers

GitHub top language GitHub code size in bytes GitHub repo file count GitHub package.json version

GitHub last commit

customer_cli looks like

customer_cli_add customer_cli_link

Go Home

Demo

customer_cli_add customer_cli_download

customer_cli_add

Go Home

Tech Stack

Server: NodeJS, ExpressJS, MongoDB, Commander

Go Home

Run Locally

Clone the project

  git clone https://github/Nik4Furi/customer_cli

Go to the project directory

  cd customer_cli

Install dependencies

  npm install

Start terminal

  node command -V (To get info our app)

  node command -h (For help, how app is work)

Go Home

Environment Variables

To run this project, you will need to add the following environment variables to your .env file also can see .env.exmaple file

Database configurations

DB_SERVER
DB_HOST
DB_PORT
DB_NAME

Go Home

Usages / Examples

To know more about a particular command you can run node command help <command>

Adding Customer into database ,customer object required ,in have firstnamename,lastname,email,phone fields are required

node command add <firstname> <lastname> <email> <phone>

//Add a customer
const addCustomer = (customer) => {
    try {
        customerModal.create(customer).then(customer => {
            console.info("new customer added");
            console.info(customer);
            mongoose.connection.close(() => { });

        }).catch((e)=>{
            console.info(e)
        })
    } catch (error) {
        console.info(error)
    }

}

Fetching or List out all the customers, name(customer name) field is required(may be included firstname or lastname)

node command find <name>

//Find customers
const findCustomer = async (name) => {
    try {
        //Remove the case incensitive
        let search = new RegExp(name, 'i');

        customerModal.find({
            $or:
                [{ firstname: search }, { lastname: search }]
        }).then(customer => {
            console.info(`${customer.length} matches`)
            console.info(customer);
            mongoose.connection.close(() => { });
        }).catch((e)=>{
            console.info(e)
        })
    } catch (error) {
        console.info(error)
    }
}

Updating the customer details, _id (customer _id) required

node command update <_id> <firstname> <lastname> <email> <phone>

//Update the list of the customers
const updateCustomer = async (_id, customer) => {
    try {
        //Find the customer of the given id
        let find = await customerModal.findById(_id)
        if (!find) {
            return console.info("given id customer did not find")
        }
        customerModal.updateOne({ _id }, { $set: { customer } }, { new: true }).
            then(customer => {
                console.info("update the details of customer")
                console.info(customer)
                mongoose.connection.close(() => { });

            }).catch((e)=>{
                console.info(e)
            })
    } catch (error) {
        console.info(error)
    }
}

Deleting one customer, _id (customer _id) is required

node command <_id>

//Delete customers
const deleteCustomer = (_id) => {
    try {
        customerModal.deleteOne({ _id }).
            then(() => {
                console.info("customer deleted")
                mongoose.connection.close(() => { });

            }).catch((e)=>{
                console.info(e)
            })
    } catch (error) {
        console.info(error)
    }
}

Deleting all the customers from database

node command deleteAll

//Delete All customers from database
const deleteAllCustomers = () => {
    customerModal.deleteMany({}).
        then(() => {
            console.info("All customers deleted")
            mongoose.connection.close(() => { });

        }).catch((e)=>{
            console.info(e)
        })
}

List our all the customers

node command list

//List the customers
const listCustomer = () => {
    try {
        customerModal.find().
            then((results) => {
                console.info(`${results.length} are encounted`)
                console.info(`${results}`)
                mongoose.connection.close(() => { });

            }).catch((e)=>{
                console.info(e)
            })
    } catch (error) {
        console.info(error)
    }
}

Go Home

Features

  • Command/Terminal(CLI,Command Line Interface) based app
  • Can do CRUD operations with customers database
  • Use MVC framework

About

A commnad line interface app, which can add , update, delete or other operations can do. Basically this app help the users can write queries into terminal for work with database in CLI.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published