Scaffolding allows us to easily create a skeleton for a web application. We manually created our public directory, added middleware, created separate route files, etc. A scaffolding tool sets up all these things for us so that we can directly get started with building our application.
The scaffolder we’ll use is called Yeoman. It is a scaffolding tool built for Node.js but also has generators for several other frameworks (such as flask, rails, django, etc.). To install yeoman, enter the following command in your terminal.
$ npm install -g yeoman
Yeoman uses generators to scaffold out applications. To check out the generators available on npm to use with yeoman, head over here. For the purpose of this tutorial, we’ll use the ‘generator-koa’. To install this generator, enter the following command in your terminal.
$ npm install -g generator-koa
To use this generator, enter β
yo koa
Then it’ll create a directory structure and will create the following files for you. It’ll also install the necessary npm modules and bower components for you.
create package.json create test/routeSpec.js create views/layout.html create views/list.html create public/styles/main.css create public/scripts/.gitkeep create controllers/messages.js create app.js create .editorconfig create .jshintrc I'm all done. Running npm install & bower install for you to install the required dependencies. If this fails, try running the command yourself.
This generator creates a very simple structure for us.
. βββ controllers β βββ messages.js βββ public | βββ scripts | βββ styles | βββ main.css βββ test | βββ routeSpec.js βββ views | βββ layout.html | βββ list.html βββ .editorconfig βββ .jshintrc βββ app.js βββ package.json
Explore the many generators available for Koa and choose the one that fits you right. Steps to working with all generators is the same. You’ll need to install a generator, run it using yeoman, it’ll ask you some questions and then create a skeleton for your application based on your answers.
Next Topic:-Click Here
Pingback: Koa.js - Logging - Adglob Infosystem Pvt Ltd
Very informative article post.Really looking forward to read more. Cool.