logic-pass-data

1.1.5 • Public • Published

logic-pass-data

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.

Piping plugin into express

//defaultPath is optional
const passDataPluginInitializer = require('logic-pass-data');
app.use(passDataPluginInitializer({
defaultPath: "/Users/dev/super-hacker"
})

Sending a page forward from the back-end:

app.get('/admin', (req,res) => 
    res.passData('pages/admin', {userType: 'admin', info: {name: 'john', age: 24, email: 'john.doe@gmail.com'}})
)

Accessing the object from the front-end

if($server.userType === 'admin')
    document.querySelector('body').innerText = $server.info.name + ', ' + $server.info.age + ', ' + $server.info.email;
//result: "john, 24, john.doe@gmail.com"

Readme

Keywords

none

Package Sidebar

Install

npm i logic-pass-data

Weekly Downloads

6

Version

1.1.5

License

ISC

Last publish

Collaborators

  • logicssoldier