Created
August 24, 2016 00:23
-
-
Save Rafase282/485aad8bc98f01b56e13b268ea9cc725 to your computer and use it in GitHub Desktop.
Example of how to import, export, and utilize functions
This file contains hidden or 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
// Load required packages | |
var User = require('../models/user'); | |
var dbHelper = require('./dbHelper'); | |
var jwt = require('jsonwebtoken'); // used to create, sign, and verify tokens | |
/* | |
EXPORTING FUNCTIONS | |
Function from the dbHelper.js file. | |
Saves object information to database and returns the apropiated results. | |
*/ | |
var objSave = function (object, res, msg) { | |
object.save(function (err) { | |
if (err) { | |
resMsg(res, 400, false, err, null); | |
} else { | |
resMsg(res, 200, true, msg, object); | |
} | |
}); | |
}; | |
exports.objSave = objSave; | |
/* EXAMPLE OF USING IMPORTED FUNCTIONS | |
* Finds All Users | |
* Returns a list of all users when found. | |
* Accessed at GET /api/users | |
*/ | |
exports.getUsers = function (req, res) { | |
var ok = 'The list of users has been succesfully generated.'; | |
var noOk = 'No users has been created yet.'; | |
var auth = 'You are not an admin.'; | |
var obj = {}; | |
dbHelper.getData(req, res, User, obj, ok, noOk, auth); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment