previous post
NodeJS http homepage 20: request url with link menu
Falah Al Fitri ・ Dec 19 '19 ・ 1 min read
#node
#http
#request
#url
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 );
Top comments (0)