Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Function as a Library

From a module we can export a module or a single function like this: // module.exports = hi;

function say_hi(name) {
    console.log('Hello ' + name)
}

console.log('Loading module')

module.exports = say_hi;
const say_hi = require('./lib2')

console.log('Hello World')

say_hi('Foo')
$ node examples/basic/app2.js

Loading module
Hello World
Hello Foo