Skip to content

Instantly share code, notes, and snippets.

View nomanHasan's full-sized avatar

Noman Hasan nomanHasan

View GitHub Profile
@nomanHasan
nomanHasan / package.json
Created September 7, 2017 18:55
Implement Nodemon in the Start Script
"scripts": {
"start": "nodemon ./bin/www"
},
@nomanHasan
nomanHasan / app.js
Last active September 7, 2017 19:00
Add Mongoose Connection
var mongoose = require('mongoose')
mongoose.connect('mongodb://127.0.0.1:27017/todoapp', { useMongoClient: true})
.then(()=> { console.log(`Succesfully Connected to the Mongodb Database at URL : mongodb://127.0.0.1:27017/todoapp`)})
.catch(()=> { console.log(`Error Connecting to the Mongodb Database at URL : mongodb://127.0.0.1:27017/todoapp`)})
@nomanHasan
nomanHasan / app.js
Created September 7, 2017 19:04
Add Bluebird Support to Mongoose
var bluebird = require('bluebird')
/*
Other Codes
*/
var mongoose = require('mongoose')
mongoose.Promise = bluebird
@nomanHasan
nomanHasan / api.route.js
Last active September 7, 2017 20:22
Api Route File #1
var express = require('express')
var router = express.Router()
var todos = require('./api/todos.route')
router.use('/todos', todos);
module.exports = router;
@nomanHasan
nomanHasan / todos.route.js
Last active September 7, 2017 20:57
Todo Route Complete
var express = require('express')
var router = express.Router()
// Getting the Todo Controller that we just created
var ToDoController = require('../../controllers/todos.controller');
// Map each API to the Controller FUnctions
@nomanHasan
nomanHasan / todo.model.js
Created September 7, 2017 19:21
Todo Model file with Mongoose paginate
var mongoose = require('mongoose')
var mongoosePaginate = require('mongoose-paginate')
var ToDoSchema = new mongoose.Schema({
title: String,
description: String,
date: Date,
status: String
})
@nomanHasan
nomanHasan / todo.service.ts
Last active September 7, 2017 19:45
Todo Service accessing the Mongoose Models
// Gettign the Newly created Mongoose Model we just created
var ToDo = require('../models/todo.model')
// Saving the context of this module inside the _the variable
_this = this
// Async function to get the To do List
exports.getTodos = async function(query, page, limit){
// Accessing the Service that we just created
var TodoService = require('../services/todos.service')
// Saving the context of this module inside the _the variable
_this = this
// Async Controller function to get the To do List
// Anatomy of a Async Function
exports.some_function = async function(){
try{
// await keyword pauses the execution of the function and returns the resolved value once completed
let value = await promise()
@nomanHasan
nomanHasan / app.js
Created September 7, 2017 20:31
Add API route to app.js
// Other Require statements ...
var index = require('./routes/index.route');
var users = require('./routes/users.route');
// Get the API route ...
var api = require('./routes/api.route')