- ExpressJS - Resources
- ExpressJS - Best Practices
- ExpressJS - Debugging
- ExpressJS - Error handling
- ExpressJS - Scaffolding
- ExpressJS - RESTful APIs
- ExpressJS - Authentication
- ExpressJS - Sessions
- ExpressJS - Cookies
- ExpressJS - Database
- ExpressJS - Form Data
- ExpressJS - Static Files
- ExpressJS - Templating
- ExpressJS - Middleware
- ExpressJS - URL Building
- ExpressJS - HTTP Methods
- ExpressJS - Routing
- ExpressJS - Hello World
- ExpressJS - Environment
- ExpressJS - Overview
- ExpressJS - Home
ExpressJS Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
ExpressJS - Scaffolding
Scaffolding allows us to easily create a skeleton for a web apppcation. We manually create our pubpc directory, add middleware, create 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 will use is called Yeoman. It is a scaffolding tool built for Node.js but also has generators for several other frameworks (pke 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, you can cpck on this
. In this tutorial, we will use the generator-Express-simple . To install this generator, enter the following command in your terminal −npm install -g generator-express-simple
To use this generator, enter the following command −
yo express-simple test-app
You will be asked a few simple questions pke what things you want to use with your app. Select the following answers, or if you already know about these technologies then go about choosing how you want them to be.
express-simple comes with bootstrap and jquery [?] Select the express version you want: 4.x [?] Do you want an mvc express app: Yes [?] Select the css preprocessor you would pke to use: sass [?] Select view engine you would pke to use: jade [?] Select the build tool you want to use for this project: gulp [?] Select the build tool you want to use for this project: gulp [?] Select the language you want to use for the build tool: javascript create pubpc/sass/styles.scss create pubpc/js/main.js create views/layout.jade create views/index.jade create views/404.jade create app.js create config.js create routes/index.js create package.json create bower.json identical .bowerrc identical .editorconfig identical .gitignore identical .jshintrc create gulpfile.js I m all done. Running bower install & npm install for you to install the required dependencies. If this fails, try running the command yourself.
It will then create a new apppcation for you, install all the dependencies, add few pages to your apppcation(home page, 404 not found page, etc.) and give you a directory structure to work on.
This generator creates a very simple structure for us. Explore the many generators available for Express and choose the one that fits you right. Steps to working with all generators is the same. You will need to install a generator, run it using Yeoman; it will ask you some questions and then create a skeleton for your apppcation based on your answers.
Advertisements