Erick91
Erick91

Reputation: 57

(intermediate value)}.then is not a function

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

Answers (2)

DevLoverUmar
DevLoverUmar

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

janmbaco
janmbaco

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

Related Questions