Reputation: 8499
I have two files, how can I pass the value to variable?
sample.js:
module.exports = {
content: [
{
table: {
body: [
[
{ text: address, alignment: 'center'}
]
}
}
}
app.js:
var sample = require('sample');
How to pass the address into the sample object?
Upvotes: 0
Views: 660
Reputation: 8323
function getContent(adress) {
return content: [
{
table: {
body: [
[
{ text: address, alignment: 'center'}
]
}
}
}
module.exports = getContent;
app.js:
var sample = require('./sample')(adress);
Upvotes: 1
Reputation: 1
You can make module.exports to be a function:
sample.js
module.exports = (address) => { return { content: [
{
table: {
body: [
{text: address, alignment: 'center'}
]
}
}
] };}
app.js
var sample = require('sample')('your address parameter');
Upvotes: 0
Reputation: 79
Try this:
module.exports = (address) => {
return {
content: [
{
table: {
body: [
{text: address, alignment: 'center'}
]
}
}
]
}
}
var sample = require('sample')('The address');
Upvotes: 0
Reputation: 73221
You want to export a function that returns an object:
module.exports = function (address) {
return {
content: [
{
table: {
body: [
{
text: address,
alignment: 'center'
}
]
}
}
]
}
};
Now you can fill the values:
var sample = require("./sample");
console.log(sample("fooAddress"));
Upvotes: 1