Trying to purge users from command line `node purge.js user`.



  • I am writing a small program in python to remove bots from forum. Learning node.js and redis from about 2 days from now on but couldn't figure it out how to use build in module nodebb/src/posts/delete.js Posts.purge.

    So my question is, is it possible to remove user and all its content from command line?

    All my tries failed, and I am not sure how code suppose to look like.


  • Admin

    You will have to init the database and then load the required module. Here is some sample code. As always make a backup of your database before running it.

    var nconf = require('nconf');
    
    nconf.file({
    	file: 'config.json'
    });
    
    var db = require('./src/database');
    
    db.init(function(err) {
    	if (err) {
    		console.log('NodeBB could not connect to your database. returned the following error: ' + err.message);
    		process.exit();
    	}
    
    	var userIdToDelete = '123';
    	var callerUid = 0;
    	var user = require('./src/user');
    	user.delete(callerUid, userIdToDelete, function (err) {
    		if (err) {
    			console.log(err.message);
    			return process.exit();
    		}
    		console.log('user id ' + userIdToDelete + ' deleted');
    		process.exit();
    	});
    });
    

    You would place this in a file in the root of your nodebb installation and run it with node filename.js. You can modify the userIdToDelete variable to delete a user by uid.



  • @baris Hm was doing similar approach, please check my another question with path.js error.


Log in to reply
 


Looks like your connection to NodeBB was lost, please wait while we try to reconnect.