Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 709 Bytes

File metadata and controls

41 lines (31 loc) · 709 Bytes

Modules on Node.js

// index.js
const {getDisplayName, getJobTitle} = require('./users.js');

setTimeout(() => {
	// Pretend this data came from some request
	const user = {
		name: 'alex',
		job: {
			title: 'software developer'
		}
	};

	const message = `${getDisplayName(user)} is a ${getJobTitle(user)}`;

	console.log(message);
}, 5000);

setTimeout(() => {}, 60000); // to keep process running
// users.js
function getDisplayName(user) {
	return user.name || 'unnamed';
}

function getJobTitle(user) {
	return (user.job && user.job.title) || 'not employed';
}

module.exports = {
	getDisplayName,
	getJobTitle
};