# Commandline tool to create user

**URL:** <https://forum.ghost.org/t/commandline-tool-to-create-user/53279>\
**Category:** Share & showcase\
**Created:** [December 13, 2024, 8:50am UTC](https://forum.ghost.org/t/commandline-tool-to-create-user/53279 "2024-12-13T08:50:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe-blocher](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/joe-blocher/32/27872_2.png) [@joe-blocher](https://forum.ghost.org/u/joe-blocher)\
**Post date:** [December 13, 2024, 8:50am UTC](https://forum.ghost.org/t/commandline-tool-to-create-user/53279/1 "2024-12-13T08:50:49Z")

</div>

Inspired by [wasaluduckworth/add-admin-user-programmatically-in-ghost](https://medium.com/@wasaluduckworth/add-admin-user-programmatically-in-ghost-3488df51df24) I have created a tool for adding users manually without the need for invite with mail.

1. Create as js-file “users.js” in the root-directory of your ghost website  

2. users.js

```auto
require('./current/core/server/models/role');
const UserModel = require('./current/core/server/models/user');
const {Command} = require('./current/node_modules/commander');
const program = new Command();

program.command('add')
    .description('Add a new user')
    .option('--name <name>', 'Name')
    .option('--email <email>', 'Email')
    .option('--password <password>', 'Password')
    .option('--role <role>', 'Role','Editor')
    .action(async (options) => {
        const {email, name, password, role} = options;

        try {
            await UserModel.User.add(
                {
                    email,
                    name,
                    password,
                    roles: [role],
                },
                {}
            );
            console.log('User added successfully.');
        } catch (err) {
            console.error('Error adding user:', err);
        }
            
       process.exit();
    });

program.parse(process.argv);

```

1. Execute

```auto
node users.js add --email editor@domain.com --name John --password atleast10chars 

```

You can add a --role too:  
Role can be Administrator || Editor || Author || Contributor  
Default: Editor
