Skip to content

Instantly share code, notes, and snippets.

@kevinchisholm
Last active February 2, 2018 23:41
Show Gist options
  • Save kevinchisholm/5aadcf9296b2b009183022cb7b62a84d to your computer and use it in GitHub Desktop.
Save kevinchisholm/5aadcf9296b2b009183022cb7b62a84d to your computer and use it in GitHub Desktop.
{
"name" : "firstNodeJsModuleExample",
"version" : "0.0.1",
"dependencies" : {
"dateTools": "file:my_modules/dateTools"
}
}
var days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
months = ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'];
function getDays () {
return days;
};
function getMonths () {
return months;
};
function getDay (dayNumber) {
return (Number.isInteger(dayNumber) && (dayNumber <= (days.length - 1))) ? days[dayNumber] : '';
};
function getMonth (monthNumber) {
return (Number.isInteger(monthNumber) && (monthNumber <= (months.length - 1))) ? months[monthNumber] : '';
};
// export the module
module.exports = {
getDays: getDays,
getMonths: getMonths,
getDay: getDay,
getMonth: getMonth
};
{
"name": "dateTools",
"description": "Example Node Module",
"private": true,
"version": "1.0.0",
"main": "index.js"
}
// require the dateTools module.
var dateTools = require('dateTools');
//demonstrate the getDay method
console.log('TEST 1: ' + dateTools.getDay(0)); //TEST 1: Monday
console.log('TEST 2: ' + dateTools.getDay(6)); //TEST 2: Sunday
//demonstrate the getMonth method
console.log('TEST 3: ' + dateTools.getMonth(0)); //TEST 3: January
console.log('TEST 4: ' + dateTools.getMonth(11)); //TEST 4: December
//demonstrate the getDays method
console.log('TEST 5: ' + dateTools.getDays()); //TEST 5: All seven days
//demonstrate the getMonths method
console.log('TEST 6: ' + dateTools.getMonths()); //TEST 6: All 12 months
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment