Reputation: 57
I am trying to generate a backup from my REST API made with node js, but when trying to execute the code that generates the backup file, it throws me that it is not a function .then(dump => { fs.writeFileSync
, this is the code with the error
var mysqlDump = require('mysqldump');
var fs = require('fs');
const dump = mysqlDump({
host: 'localhost',
user: 'root',
password: '',
database: 'demo',
tables:['sales_orders'], // only these tables
// where: {'estado': 'id < 1000'}, // Only test players with id < 1000
//ifNotExist:true, // Create table if not exist
}.then(dump => {
fs.writeFileSync('test.sql', dump); // Create data.sql file with dump result
}));
module.exports = dump;
Upvotes: 1
Views: 484
Reputation: 13933
You have a closing ')' at the wrong place:
Your Code
var mysqlDump = require('mysqldump');
var fs = require('fs');
const dump = mysqlDump({
host: 'localhost',
user: 'root',
password: '',
database: 'demo',
tables:['sales_orders'], // only these tables
// where: {'estado': 'id < 1000'}, // Only test players with id < 1000
//ifNotExist:true, // Create table if not exist
}.then(dump => { //missing at this line
fs.writeFileSync('test.sql', dump); // Create data.sql file with dump result
})); //extra at this line
module.exports = dump;
Corrected code block
var mysqlDump = require('mysqldump');
var fs = require('fs');
const dump = mysqlDump({
host: 'localhost',
user: 'root',
password: '',
database: 'demo',
tables:['sales_orders'], // only these tables
// where: {'estado': 'id < 1000'}, // Only test players with id < 1000
//ifNotExist:true, // Create table if not exist
}).then(dump => {
fs.writeFileSync('test.sql', dump); // Create data.sql file with dump result
});
module.exports = dump;
To avoid this type of problems, use VS code with linting extentions to highlight code inconsistencies.
Upvotes: 1
Reputation: 350
There is missing ")" closing tag after }). Try this:
var mysqlDump = require('mysqldump');
var fs = require('fs');
const dump = mysqlDump({
host: 'localhost',
user: 'root',
password: '',
database: 'demo',
tables:['sales_orders'], // only these tables
// where: {'estado': 'id < 1000'}, // Only test players with id < 1000
//ifNotExist:true, // Create table if not exist
}).then(dump => {
fs.writeFileSync('test.sql', dump); // Create data.sql file with dump result
});
module.exports = dump;
Upvotes: 0