Overview
One of the most frequently asked features from MEAN users are a to scaffold their applications. As we looked for a by-community build and deploy production level MEAN applications, we decided-go with a Yeoman Generator. Yeoman Generators provides a powerful, easy-to-maintain, and open solution for scaffolding applications.
So, we set off to work on the features we thought every developer needs, and we is proud to present the official MEAN. JS Yeoman Generator. It includes a set of simple tools, you can use the Make your MEAN application development easier and the.
Getting Started
Before you to begin make sure you have the Yo Scaffolding tool installed (as it's part of the Yeoman tool set, you might has Installed it before). To globally install yo 'll need to use NPM:
$ npm install-g yo
Note: Your user might not has the permissions to install package globally, so use a super user or sudo.
Once you has yo installed, you'll need to install the MEAN. JS Generator as well:
$ NPM install-g Generator-meanjs
Started with the MEAN. JS Generator. The generator would help you create a MEAN. JS application, a CRUD module, Angular module, and other angularjs/express entities. We ' ll begin with the application generator.
Application Generator
The application generator would help you create a fresh copy of a MEAN. JS application in your working folder. To create your MEAN application, navigate to a new project folder, and then use the yo to generate your application:
$ Yo Meanjs
The generator would ask you a few questions about your new application and would generate it for you. When the installation process was over, you'll be able to use grunt to run your new MEAN application:
$ grunt
Now, the application generator does a great job scaffolding a whole application, but daily work requires us to repeat a lo T of structured code. For the purpose we provided you and some sub-generators to the help your speed up your development.
CRUD Module Sub-generator
The Crud module Sub-generator would help you create a new CRUD module, similar to the article sample provided with the Proj Ect. To create a new CRUD module you'll need to use yo again:
$ Yo meanjs:crud-module <module-name>
This would create both AngularJS and Express files supporting full CRUD functionality, and add the Karma and Mocha tests.
Note: Don ' t forget to use your module name as a argument when calling the CRUD module Sub-generator.
AngularJS Module Sub-generator
Another redundant task is creating a new AngularJS module structure. For this purpose you can use the Angular module sub-generator. It'll create the proper folder structure for you and the module initialization file. Creating a new AngularJS module is simple:
$ Yo meanjs:angular-module <module-name>
The sub-generator would ask for more information about your folder structure, and would create the empty new AngularJS Modul E. Now, to fill the new module with your business logic, we provided you with several AngularJS entities sub-generators.
AngularJS Route Sub-generator
To construct your module, you'll often need to create a new route. The AngularJS Route sub-generator would help you create a view, controller and a proper route in your module routes.js< /c0> file. If it can ' t find the module routes file The Sub-generator would create one for you. Creating a new AngularJS route would involve executing this command:
$ Yo meanjs:angular-route <route-name>
The sub-generator would ask for more information about your controller, view and routing URL, and would generate the APPROPR iate files for you.
AngularJS Controller Sub-generator
The AngularJS controller Sub-generator would create a new AngularJS controller in the specified module ' s controllers folder. To create a new AngularJS controller run yo again by using the This command:
$ Yo meanjs:angular-controller <controller-name>
The sub-generator would ask you for the module name under which your would like to create your new controller, and would crea Te a new AngularJS controller file in this module Controllers folder and a controller test in the module test S folder.
Don ' t forget! This is the controller name as an argument.
AngularJS View Sub-generator
Once you has your controller file ready and you are want to add a view that makes use of the this controller. The AngularJS view Sub-generator would create a new AngularJS view in thr specified module ' s views folder, and Wil L allow you to add a route definition for it. To create a new AngularJS view you'll need to the execute this command:
$ Yo Meanjs:angular-view <view-name>
The sub-generator would ask you for the module name under which you would like to create your new view, and some additional Routing information. It would then create a new view file with that module ' s view folder and add a routing state to the moduleroutes . js file. If it can ' t find the module routes file It'll create one for you.
AngularJS Service Sub-generator
The AngularJS service Sub-generator would create a new AngularJS service in the specified module ' s Services folder . To create a new AngularJS service, you'll need to the execute this command:
$ Yo meanjs:angular-service <service-name>
The sub-generator would ask you for the module name under which your would like to create your new service, and would create A new AngularJS service file in the that module ' s Services folder.
AngularJS Directive Sub-generator
The AngularJS directive Sub-generator would create a new AngularJS directive in the specified module ' s directives Folder. Creating a new AngularJS directive should already look familiar:
$ Yo meanjs:angular-directive <directive-name>
The sub-generator would ask you for the module name under which your would like to create your new directive, and would creat e A new AngularJS directive file in that module ' s Directives folder.
AngularJS Filter Sub-generator
The AngularJS filter Sub-generator would create a new AngularJS filter in a specified module ' s Filters folder. To create a new AngularJS filter need to call Yo again:
$ Yo meanjs:angular-filter <filter-name>
The sub-generator would ask you for the module name under which you would like to create your new filter, and would create a New AngularJS filter file in this module Filters folder.
AngularJS Config Sub-generator
The AngularJS config Sub-generator would create a new AngularJS config section in a specified module ' s config fold Er. To create a new AngularJS config file just call yo:
$ Yo meanjs:angular-config <config-name>
The sub-generator would ask you for the module name under which you would like to create your new config, and would create a New AngularJS config file in the that module ' config folder.
AngularJS Test Sub-generator
Your MEAN application comes pre-bundled with the Karma Test Runner and Jasmine testing framework. To test your AngularJS controllers you'll need to create a test file, which Karma would later use to run the tests. For this purpose we provided, with the AngularJS test Sub-generator. Creating A new AngularJS test is effortless, just execute this command:
$ Yo meanjs:angular-test <controller-name>
This would create a test file for your controller, and if the sub-generator doesn ' t find the specified controller file, it Would create one for you.
Don ' t forget! You ' re suppose to pass the controller name as an argument.
Express Model Sub-generator
Often you'll find the need to just create a single Express model. The Express model Sub-generator you and creating a express model in the app/models folder. To create a new model just use yo:
$ Yo Meanjs:express-model <model-name>
This would create a new empty model in the app/models folder and a new model test in the app/tests folder .
Note: It is recommended-Avoid naming your model in plural form and use a singular form instead. I.e article and not articles
Express Controller Sub-generator
Another recurring task is creating an empty Express controller. The Express controller Sub-generator would help you with creating a Express controller in the app/controllers fol Der. To create a new controller just use yo:
$ Yo meanjs:express-controller <controller-name>
This would create a new empty controller in the app/controllers folder.
Express Routes Sub-generator
To make HTTP requests to your controller methods you'll need to use a routing file in the app/routes folder. The Express routes Sub-generator would help you to add a new empty routes file. To create a new routes file execute this yo command:
$ Yo meanjs:express-route <route-name>
This would create a new empty route file in the app/routes folder.
Express Test Sub-generator
Your MEAN application comes pre-bundled with the Mocha testing framework. To test your Express models your ' ll need to create a new test file, which Mocha would use while running tests. For this purpose we provided your with the Express test Sub-generator. Creating A new Express test is easy, just execute this command:
$ Yo meanjs:express-test <model-name>
This would create a test file for your Express model, and if the sub-generator doesn ' t find the specified model, it would CR Eate one for you.
Don ' t forget! You ' re suppose to pass the model name as an argument.
Meanjs Yo Generator