- Koa.js - Resources
- Koa.js - Scaffolding
- Koa.js - Logging
- Koa.js - RESTful APIs
- Koa.js - Database
- Koa.js - Caching
- Koa.js - Compression
- Koa.js - Authentication
- Koa.js - Sessions
- Koa.js - Cookies
- Koa.js - Static Files
- Koa.js - File Uploading
- Koa.js - Form Data
- Koa.js - Templating
- Koa.js - Cascading
- Koa.js - Error Handling
- Koa.js - Redirects
- Koa.js - Response Object
- Koa.js - Request Object
- Koa.js - HTTP Methods
- Koa.js - URL Building
- Koa.js - Routing
- Koa.js - Generators
- Koa.js - Hello World
- Koa.js - Environment
- Koa.js - Overview
- Koa.js - Home
Koa.js Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Koa.js - Scaffolding
Scaffolding allows us to easily create a skeleton for a web apppcation. We manually created our pubpc 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 apppcation.
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 apppcations. To check out the generators available on npm to use with yeoman, head over
. 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/pst.html create pubpc/styles/main.css create pubpc/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 ├── pubpc | ├── scripts | └── styles | └── main.css ├── test | └── routeSpec.js ├── views | ├── layout.html | └── pst.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 apppcation based on your answers.
Advertisements