Skip to content

Instantly share code, notes, and snippets.

View zeptobook's full-sized avatar

ZeptoBook zeptobook

View GitHub Profile
@zeptobook
zeptobook / indexOf.js
Created December 30, 2018 14:55
array.indexOf()
var names = ['Frank', 'Charles', 'Dolly', 'Robert', 'Bob'];
var pos = names.indexOf("Dolly");
@zeptobook
zeptobook / lastIndexOf.js
Created December 30, 2018 15:06
array.lastIndexOf()
var names = ['Frank', 'Charles', 'Dolly', 'Robert', 'Bob'];
var pos = names.lastIndexOf("Charles");
@zeptobook
zeptobook / package.json
Created January 5, 2019 19:15
product-app package.json
{
"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"
@zeptobook
zeptobook / package.json
Created January 5, 2019 19:23
After Installing pacakages
{
"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",
@zeptobook
zeptobook / server.js
Last active January 6, 2019 02:44
server file
// 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())
@zeptobook
zeptobook / config.js
Last active January 6, 2019 01:05
config.js
module.exports = {
url: 'mongodb://<dbUserName>:<dbUserPassword>@ds251002.mlab.com:51002/adeshtestdb',
serverport: 3000
}
@zeptobook
zeptobook / server.js
Created January 5, 2019 23:47
Connecting to db
// 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(() => {
@zeptobook
zeptobook / server.js
Last active January 6, 2019 01:04
Updating server port
// listen on port 3000
app.listen(config.serverport, () => {
console.log("Server is listening on port 3000");
});
@zeptobook
zeptobook / product.model.js
Last active January 6, 2019 00:05
Product Model
const mongoose = require('mongoose');
const ProductSchema = mongoose.Schema({
title: String,
description: String,
price: Number,
company: String
}, {
timestamps: true
});
@zeptobook
zeptobook / product.controller.js
Last active January 6, 2019 02:13
All product related functions
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"
});
}