Blog

Node.js module.exports and require Examples
Posted on July 22, 2019 in Node.js by Matt Jennings

band.js Output

module.exports = {
    punk: 'Sex Pistols',
    rap: 'Public Enemy',
    classic: 'Rolling Stones'
};

run.js Output

var bands = require('./band.js');

for(var prop in bands) {
    console.log(bands[prop]);
}

console.log Output Using Node.js

Sex Pistols
Public Enemy
Rolling Stones

Leave a Reply