an express plugin by LogicsSoldier
passData - is an expressjs plugin used to embed JavaScript objects in HTML documents and send them to the client. The object can be found in the $server variable on the front-end.
//defaultPath is optional
const passDataPluginInitializer = require('logic-pass-data');
app.use(passDataPluginInitializer({
defaultPath: "/Users/dev/super-hacker"
})
app.get('/admin', (req,res) =>
res.passData('pages/admin', {userType: 'admin', info: {name: 'john', age: 24, email: 'john.doe@gmail.com'}})
)
if($server.userType === 'admin')
document.querySelector('body').innerText = $server.info.name + ', ' + $server.info.age + ', ' + $server.info.email;
//result: "john, 24, john.doe@gmail.com"