My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

What's the best way to add a default admin user in NodeJS/MongoDB app?

Argjend's photo
Argjend
·Jun 23, 2017

So I have an application developed in NodeJS, which is using the MongoDB for database (with Mongoose). Besides the application, there is an admin panel where administrators can manage all the data being added by regular users.

In the users schema, I have the following prop:

role: {
    type: String,
    default: "user",
    enum: ["user", "admin"]
},

My question is, what's the best/secure way to add one or two admin users?