Skip to content

Instantly share code, notes, and snippets.

@xApnea
Created June 19, 2020 21:13
Show Gist options
  • Save xApnea/e4ca7ef1153e851ec7f1818c85097b71 to your computer and use it in GitHub Desktop.
Save xApnea/e4ca7ef1153e851ec7f1818c85097b71 to your computer and use it in GitHub Desktop.
const express = require('express');
const app = express();
const Product = require('../db/model.js')
const port = 3000;
app.use(express.static('dist'));
app.get('/api/products', (req, res) => {
const id = req.query.id;
Product.findById(id)
.then((product) => {
console.log(product);
res.status(200).send(product);
});
});
app.listen(port, () => console.log(`Listening at http://localhost:${port}`));
//Returned Data from querying above request with id "5eec29ed009ae7f194ad98da":
{
"_id": "5eec29ed009ae7f194ad98da",
"title": "Unbranded Plastic Gloves",
"description": "Ipsum cupiditate provident debitis minus necessitatibus iure ut maxime. Voluptas quaerat dolor exercitationem doloribus expedita reprehenderit vel ipsum. Et voluptas quaerat laboriosam aliquid eaque id dolorem esse. Consequatur nemo aspernatur nihil suscipit.",
"__v": 0,
"variations": [
{
"color": "black",
"cost": 779,
"_id": "5eec29ed009ae7f194ad98db",
"images": [
{
"src": "http://lorempixel.com/846/1038",
"_id": "5eec29ed009ae7f194ad98df"
},
{
"src": "http://lorempixel.com/846/1038",
"_id": "5eec29ed009ae7f194ad98de"
},
{
"src": "http://lorempixel.com/846/1038",
"_id": "5eec29ed009ae7f194ad98dd"
},
{
"src": "http://lorempixel.com/846/1038",
"_id": "5eec29ed009ae7f194ad98dc"
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment