This is just a code related doubt and not anything project related! I am using variables in the server-side code to get data from APIs or from NPM packages. But how do use the same variables in client-side? Here’s an example of what I mean:
api.projects.get({ domain: 'khaleelgibran' }).then(project => console.log(project))
I’m using this statement in my server-side code to get some data (called project
) using the Glitch API. Here, it’s console.log
ing the project
. But is there any way, I can send this data to client-side, which I can then manipulate and do whatever I like using DOM in the client-side (like showing it in my webpage)?
If you create a scope (a variable with an object context, e.g. var myScope = {};
) you can use lodash on the server to access the object. If you’re working with express you can create a plugin that takes some lodash query and returns it to a client.
1 Like
I meant more like in a POST request???
If you have already been using any of HTTP servers like express
or koa
, etc., then you have to check your library’s docs for how to handle the requests.
In express
you can do this:
// Client-side
const data = await get('/project/xxx')
document.write(data)
// Server-side
require ('express')().get('/project/:id', (req, res) => res.json(getProjectData(req.params.id)))