loading...

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 =  `
                <ul>
                    <li><a href="/" >Home</a></li>
                    <li><a href="/about" >About</a></li>
                </ul>
            `;

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>
            </ul>` 
          );

replace with

res.write( menu );

Thank for reading :)

Discussion

pic
Editor guide