From the course: TypeScript for Node.js Developers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

How to use enums in Node.js

How to use enums in Node.js

From the course: TypeScript for Node.js Developers

Start my 1-month free trial

How to use enums in Node.js

- [Instructor] Enums are a great way to set a series of values that don't change or are immutable. For example, it could be used for a settings files. Let's take a look at what it looks like. So what we're going to do in the root folder of our project, we'll create a brand new file. And we'll call this one settings.ts. And then in this settings files, we'll set our enums. So enums can be strings, numbers, or a combination. And by the way, these are constants. So when you create enums, these are not changeable. So make sure you understand that when you create enums. And I'm going to put it in the notes. Enums are constants. All right, so let's go ahead and export our enum and we'll call this one Settings, and it basically goes like this for the syntax. Curly braces and that's it. And then you can set all the properties inside the Settings enum. So, mlabUser. And what we're going to do is basically do the same as we've done here in our index.ts. So we're going to do all these particular…

Contents