how to pass res.send(variable) to a variable in express









up vote
-1
down vote

favorite












I created an express app that use a function searchUrls() from another JavaScript file.
this function return a variable Res.
i can show it's value by res.send(Res) or res.json(Res).
but i want to pass the value to another variable.






const express = require('express');

const app = express();

const script = require('./script');

app.get('/search/:itemID', (req, res) =>
script
.searchUrls(req.params.itemID)
.then(Res =>
res.json(Res);
);
);

const port = process.env.PORT || 3000;
app.listen(port, () =>
console.log(`Listening on $port`);
)












share|improve this question





















  • I am a bit confused about what you want to achieve, do you want to save the variable "Res", add some extra information to it or?
    – Lagoni
    Nov 10 at 20:11










  • The terminology is confusing, so it's unclear what you're trying to achieve. searchUrls doesn't return a variable, it returns a promise. Res isn't a variable, it's a parameter. another variable - what is that?
    – estus
    Nov 10 at 20:16










  • yes i want to save it. so i can work with it
    – rachid elaid
    Nov 10 at 20:19










  • @rachidelaid What does 'work with it' mean? Do you want to cache it or else? Where you want to use this 'variable'? The code you posted doesn't illustrate your intentions, and the description doesn't really help to understand them.
    – estus
    Nov 10 at 20:31











  • sorry for that. i just want to add it to an array
    – rachid elaid
    Nov 10 at 20:55














up vote
-1
down vote

favorite












I created an express app that use a function searchUrls() from another JavaScript file.
this function return a variable Res.
i can show it's value by res.send(Res) or res.json(Res).
but i want to pass the value to another variable.






const express = require('express');

const app = express();

const script = require('./script');

app.get('/search/:itemID', (req, res) =>
script
.searchUrls(req.params.itemID)
.then(Res =>
res.json(Res);
);
);

const port = process.env.PORT || 3000;
app.listen(port, () =>
console.log(`Listening on $port`);
)












share|improve this question





















  • I am a bit confused about what you want to achieve, do you want to save the variable "Res", add some extra information to it or?
    – Lagoni
    Nov 10 at 20:11










  • The terminology is confusing, so it's unclear what you're trying to achieve. searchUrls doesn't return a variable, it returns a promise. Res isn't a variable, it's a parameter. another variable - what is that?
    – estus
    Nov 10 at 20:16










  • yes i want to save it. so i can work with it
    – rachid elaid
    Nov 10 at 20:19










  • @rachidelaid What does 'work with it' mean? Do you want to cache it or else? Where you want to use this 'variable'? The code you posted doesn't illustrate your intentions, and the description doesn't really help to understand them.
    – estus
    Nov 10 at 20:31











  • sorry for that. i just want to add it to an array
    – rachid elaid
    Nov 10 at 20:55












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I created an express app that use a function searchUrls() from another JavaScript file.
this function return a variable Res.
i can show it's value by res.send(Res) or res.json(Res).
but i want to pass the value to another variable.






const express = require('express');

const app = express();

const script = require('./script');

app.get('/search/:itemID', (req, res) =>
script
.searchUrls(req.params.itemID)
.then(Res =>
res.json(Res);
);
);

const port = process.env.PORT || 3000;
app.listen(port, () =>
console.log(`Listening on $port`);
)












share|improve this question













I created an express app that use a function searchUrls() from another JavaScript file.
this function return a variable Res.
i can show it's value by res.send(Res) or res.json(Res).
but i want to pass the value to another variable.






const express = require('express');

const app = express();

const script = require('./script');

app.get('/search/:itemID', (req, res) =>
script
.searchUrls(req.params.itemID)
.then(Res =>
res.json(Res);
);
);

const port = process.env.PORT || 3000;
app.listen(port, () =>
console.log(`Listening on $port`);
)








const express = require('express');

const app = express();

const script = require('./script');

app.get('/search/:itemID', (req, res) =>
script
.searchUrls(req.params.itemID)
.then(Res =>
res.json(Res);
);
);

const port = process.env.PORT || 3000;
app.listen(port, () =>
console.log(`Listening on $port`);
)





const express = require('express');

const app = express();

const script = require('./script');

app.get('/search/:itemID', (req, res) =>
script
.searchUrls(req.params.itemID)
.then(Res =>
res.json(Res);
);
);

const port = process.env.PORT || 3000;
app.listen(port, () =>
console.log(`Listening on $port`);
)






javascript node.js express






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 20:03









rachid elaid

42




42











  • I am a bit confused about what you want to achieve, do you want to save the variable "Res", add some extra information to it or?
    – Lagoni
    Nov 10 at 20:11










  • The terminology is confusing, so it's unclear what you're trying to achieve. searchUrls doesn't return a variable, it returns a promise. Res isn't a variable, it's a parameter. another variable - what is that?
    – estus
    Nov 10 at 20:16










  • yes i want to save it. so i can work with it
    – rachid elaid
    Nov 10 at 20:19










  • @rachidelaid What does 'work with it' mean? Do you want to cache it or else? Where you want to use this 'variable'? The code you posted doesn't illustrate your intentions, and the description doesn't really help to understand them.
    – estus
    Nov 10 at 20:31











  • sorry for that. i just want to add it to an array
    – rachid elaid
    Nov 10 at 20:55
















  • I am a bit confused about what you want to achieve, do you want to save the variable "Res", add some extra information to it or?
    – Lagoni
    Nov 10 at 20:11










  • The terminology is confusing, so it's unclear what you're trying to achieve. searchUrls doesn't return a variable, it returns a promise. Res isn't a variable, it's a parameter. another variable - what is that?
    – estus
    Nov 10 at 20:16










  • yes i want to save it. so i can work with it
    – rachid elaid
    Nov 10 at 20:19










  • @rachidelaid What does 'work with it' mean? Do you want to cache it or else? Where you want to use this 'variable'? The code you posted doesn't illustrate your intentions, and the description doesn't really help to understand them.
    – estus
    Nov 10 at 20:31











  • sorry for that. i just want to add it to an array
    – rachid elaid
    Nov 10 at 20:55















I am a bit confused about what you want to achieve, do you want to save the variable "Res", add some extra information to it or?
– Lagoni
Nov 10 at 20:11




I am a bit confused about what you want to achieve, do you want to save the variable "Res", add some extra information to it or?
– Lagoni
Nov 10 at 20:11












The terminology is confusing, so it's unclear what you're trying to achieve. searchUrls doesn't return a variable, it returns a promise. Res isn't a variable, it's a parameter. another variable - what is that?
– estus
Nov 10 at 20:16




The terminology is confusing, so it's unclear what you're trying to achieve. searchUrls doesn't return a variable, it returns a promise. Res isn't a variable, it's a parameter. another variable - what is that?
– estus
Nov 10 at 20:16












yes i want to save it. so i can work with it
– rachid elaid
Nov 10 at 20:19




yes i want to save it. so i can work with it
– rachid elaid
Nov 10 at 20:19












@rachidelaid What does 'work with it' mean? Do you want to cache it or else? Where you want to use this 'variable'? The code you posted doesn't illustrate your intentions, and the description doesn't really help to understand them.
– estus
Nov 10 at 20:31





@rachidelaid What does 'work with it' mean? Do you want to cache it or else? Where you want to use this 'variable'? The code you posted doesn't illustrate your intentions, and the description doesn't really help to understand them.
– estus
Nov 10 at 20:31













sorry for that. i just want to add it to an array
– rachid elaid
Nov 10 at 20:55




sorry for that. i just want to add it to an array
– rachid elaid
Nov 10 at 20:55

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242934%2fhow-to-pass-res-sendvariable-to-a-variable-in-express%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242934%2fhow-to-pass-res-sendvariable-to-a-variable-in-express%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

What does pagestruct do in Eviews?

Dutch intervention in Lombok and Karangasem

Channel Islands