NodeJS http homepage 30: create custom module and export

antelove19 profile image Falah Al Fitri ・1 min read

Happy Coding

previous post

DRY is Don't Repeat Yourself, which will be used in link menu.

We will create custom module and export it.

create a file: public/partials/menu.js and write code such as:

var link =  `
                    <li><a href="/" >Home</a></li>
                    <li><a href="/about" >About</a></li>

module.exports = link

In index.js, add require menu file

const menu  = require('../public/partials/menu');

for each

res.write( `<ul>
                <li><a href="/" >Home</a></li>
                <li><a href="/about" >About</a></li>

replace with

res.write( menu );

Thank for reading :)


Editor guide