Home »
Node.js
Express template generator for your projects (2) | A study of the application structure
Express template generator: Here, we are going to see how we can generate a prepared template for express projects?
Submitted by Godwill Tetah, on June 25, 2019
Hello! In express template generator for your projects (1), we looked at express generator and how we can start an express application with stressing to build a brand new structure of all required files.
Express generator automatically generates a standard structure or template for an express application.
Express generator is a tool that helps us build a standard structure or template of the express application with some code to start up.
It includes all required modules and dependencies which you'll later install and use.
Take Note! You should have Node js installed in your computer.
With Node.js already up and running, let's get started.
We saw how the structure looks like and generated a project example called myapp.
Now, let's explain the meaning of the application structure:
- The Bin folder contains a file that contains some server details like port number, required modules and some basic error handling. The file mostly comes with the name www.
- Changes are rarely made in this folder.
- The Public folder: As the name implies, it's a folder for public use. Therefore, all the resources used or viewed by your users are stored in this folder. These resources could be images, JavaScript and CSS as seen below.
- Routes: Routing is a terms that describes the technique of creating different sub domains with separate web pages or documents. For example, a route could be .../home , .../blog ,.../about and ...users.
The folder route stores the various route files. By default express generator configures 2 route files which are index.js and users.js.
- Views: views are how data can be rendered in html using template engines.
If no specific template engine is configured, it uses jade also known pug by default.
- App.js: app.js is the main file that is initiated at the command prompt. It’s the main express application file that joins all other parts together. It requires all required modules, connects file routes, connects to template engine or views, connects to middleware.
- Package.json file: The package.json file is a file with accurate details about your application. It contains details such as author, name, version, dependencies, etc.
Below is an example of a package.json file for an express generated project.
Thanks for coding with me. Your comments are most welcome.