This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var names = ['Frank', 'Charles', 'Dolly', 'Robert', 'Bob']; | |
var pos = names.indexOf("Dolly"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var names = ['Frank', 'Charles', 'Dolly', 'Robert', 'Bob']; | |
var pos = names.lastIndexOf("Charles"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "product-app", | |
"version": "1.0.0", | |
"description": "This is zepbook product app", | |
"main": "server.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "ZeptoBook", | |
"license": "MIT" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "product-app", | |
"version": "1.0.0", | |
"description": "This is zepbook product app", | |
"main": "server.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "ZeptoBook", | |
"license": "MIT", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get dependencies | |
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const app = express(); | |
// parse requests | |
app.use(bodyParser.urlencoded({ extended: false })) | |
app.use(bodyParser.json()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
url: 'mongodb://<dbUserName>:<dbUserPassword>@ds251002.mlab.com:51002/adeshtestdb', | |
serverport: 3000 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Configuring the database | |
const config = require('./config.js'); | |
const mongoose = require('mongoose'); | |
mongoose.Promise = global.Promise; | |
// Connecting to the database | |
mongoose.connect(config.url, { | |
useNewUrlParser: true | |
}).then(() => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// listen on port 3000 | |
app.listen(config.serverport, () => { | |
console.log("Server is listening on port 3000"); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mongoose = require('mongoose'); | |
const ProductSchema = mongoose.Schema({ | |
title: String, | |
description: String, | |
price: Number, | |
company: String | |
}, { | |
timestamps: true | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Product = require('./product.model.js'); | |
//Create new Product | |
exports.create = (req, res) => { | |
// Request validation | |
if(!req.body) { | |
return res.status(400).send({ | |
message: "Product content can not be empty" | |
}); | |
} |