Project Directory Structure

The project is organized into the following directory structure:

Image ./: Contains the base application files and supporting folders. This is the project root.

Image ./npm_modules: Created when the NPMs listed above are installed in the system.

Image ./controllers: Contains the Express route controllers that provide the interaction between routes and changes to the MongoDB database.

Image ./models: Contains the Mongoose model definitions for objects in the database.

Image ./static: Contains any static files that need to be sent, such as CSS and AngularJS code.

Image ./views: Contains the HTML templates that will be rendered by EJS.

Image ../images: Contains any images for the project. This is at a peer level to the project so that multiple projects can use the same images.

Image ../lib: Contains the AngularJS libraries so that multiple projects can load them locally. In production, you may want to use a CDN delivery address instead.


Note

This is just one method of organizing your code. You do not have to follow this directory structure, but keep in mind that directory structure should be part of the overall design of your projects so that you can easily find the code you are looking for.


In addition to the directory structure, the following code files are included. This list is intended to give you an idea of the functionality of each file:

Image ./cart_init.js: Provides standalone initialization code for this example. It creates a single customer named customerA and adds several products to use in the example.

Image ./cart_server.js: Loads the necessary libraries, creates a connection to MongoDB, and starts the Express server. This is the main application file.

Image ./cart_routes.js: Defines the routes for the Express server. This file handles functionality that does not interact with the database.

Image ./controllers/customers_controller.js: Defines the functionality for the routes that require interaction with the MongoDB database to get and update customer data, such as cart, shipping, and billing information.

Image ./controllers/orders_controller.js: Defines the functionality for the routes that require interaction with the MongoDB database to get the order objects.

Image ./controllers/products_controller.js: Defines the functionality for the routes that require interaction with the MongoDB database to get one or all of the product objects.

Image ./models/cart_model.js: Defines the customer, product, order, and supporting models for the cart example.

Image ./views/shopping.html: Provides the main shopping page for the application, which allows the user to view products and place them into the cart.

Image ./static/billing.html: Implements the billing information view. This is an AngularJS partial template.

Image ./static/cart.html: Implements the shopping cart view. This is an AngularJS partial template.

Image ./static/orders.html: Implements a view with a list of orders. This is an AngularJS partial template.

Image ./static/products.html: Implements a list of products view. This is an AngularJS partial template.

Image ./static/product.html: Implements a view for a single product with an Add to Cart button. This is an AngularJS partial template.

Image ./static/review.html: Implements a view to allow the user to review the order before placing it. This is an AngularJS partial template.

Image ./static/shipping.html: Implements the shipping information view. This is an AngularJS partial template.

Image ./static/js/cart_app.js: Provides the AngularJS module and controller definitions to handle all the shopping cart interaction between the AngularJS code and the webserver.

Image ./static/css/cart_styles.css: Provides the CSS styling for the AngularJS HTML pages.


Note

The example in this chapter needs data to be initialized in the database. If you want to follow along with the examples, please look at the “Initializing the Application” section at the end of this chapter for instructions on how to initialize the data.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.116.102