How to Create Modules Using the CLI

Create the module in the current folder

So we’ve covered the metadata of the @NgModule decorator, and now it’s time to start creating our own modules. Now that we know the structure of a NgModule class, we could start writing our modules by hand, but thankfully, the Angular CLI team has created a way to generate modules with a few simple commands.

To create a new module using the CLI, we use the generate command. We’ve already used this command to generate new components in our example application. The full command for creating a module is as follows:

ng generate module <modulename>

So if we wanted to create a new module named AdminModule, we would simply use this command:

ng generate module AdminModule

Or use the shortcut format as follows:

ng g module AdminModule

Get hands-on with 1200+ tech skills courses.