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`);
)javascript node.js express
add a comment |
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`);
)javascript node.js express
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.searchUrlsdoesn't return a variable, it returns a promise.Resisn'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
add a comment |
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`);
)javascript node.js express
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
javascript node.js express
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.searchUrlsdoesn't return a variable, it returns a promise.Resisn'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
add a comment |
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.searchUrlsdoesn't return a variable, it returns a promise.Resisn'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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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.
searchUrlsdoesn't return a variable, it returns a promise.Resisn'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