1.1.5 • Published 9 years ago

logic-pass-data v1.1.5

Weekly downloads
-
License
ISC
Repository
-
Last release
9 years ago

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"
1.1.5

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.5

9 years ago

1.0.0

9 years ago