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.
Server: NodeJS, ExpressJS, MongoDB, Commander
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)
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
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)
}
}
- Command/Terminal(CLI,Command Line Interface) based app
- Can do CRUD operations with customers database
- Use MVC framework