Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
var bodyParser = require("body-parser");
var mongoose = require("mongoose");
mongoose.connect('mongodb://localhost/dayanand-sagar-souvnir-store');
var Product = require("./Schema/product");
var Wishlist = require("./Schema/wishlist");
var app = express();
app.use(bodyParser.json());
app.get("/", function(request, response){
response.send("Home page");
});
app.get("/products", function(req, res) {
Product.find({}, function(err, products) {
if(err) {
res.status(500).send({error: "Some internal error. If problem persist, please contant us and report the issue"});
} else {
res.send(products);
}
});
});
app.get("/products/:categories", function(req, res) {
var cat = req.params.categories;
Product.find({"categories": cat}, function(err, products) {
if(err) {
res.status(500).send({error: "Some internal error. If problem persist, please contant us and report the issue"});
} else {
res.send(products);
}
});
});
app.post("/product", function(request, response){
var prod = request.body;
if(Object.keys(prod).length == 0) {
response.status(500).send({error: "No product is present"});
} else {
var product = new Product();
product.title = prod.title;
product.price = prod.price;
product.description = prod.description;
product.save(function(err, storedProduct) {
if(err) {
response.status(500).send(
{error: "enable to save the product in the database"});
} else {
response.status(200).send(storedProduct);
}
});
}
});
app.post("/wishlist", function(request, response) {
var wishlist = new Wishlist();
var title = request.body.title;
if(title) {
wishlist.title = title;
}
wishlist.save(function(err, wishlistObj){
if(err) {
response.status(500).send({error:"Unable to create wishlist"});
} else {
response.send("wishlist created successfully");
}
});
});
app.put("/wishlist/product/add", function(request, response) {
var prodId = request.body.productId;
Product.findOne({_id: prodId}, function(err, product) {
if(err) {
response.status(500).send(
{error: "Product donest exit in the database"});
} else {
Wishlist.update({_id: request.body.wishlistId},
{$addToSet: {products: product._id}},
function(err, wishList) {
if(err) {
response.status(500).send(
{error: "unable to add the product to the wishlist"});
} else {
response.send("Successfully added the product in the wishlist");
}
});
}
});
});
app.get("/wishlist", function(request, response) {
Wishlist.find({}).populate({path: 'products', model: 'Product'})
.exec(function(err, wishlist) {
if(err) {
response.status(500).send({error: "Unable to fetch the wishlist"});
} else {
response.send(wishlist);
}
});
});
app.listen(3004, function() {
console.log("Server is up and running on Port 3004");
});
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team