Posted onEdited onViews: Disqus: Symbols count in article: 13kReading time ≈12 mins.
Introduction(说明):
Menu(菜单):
signup(注册):
Products(商品):
Shopping cart(购物车):
Checkout(填写订单):
Order(订单):
Comment(建议):
Last semester did a Praktikum in a german company, the main job was independently building an eCommerce Platform to sell german products to China customers, and this Website is the outcome. It should have more functions, but due to Corona-virus, the plan was forced to be interrupted, and more content will be perfected one after another.
This eCommerce Platform was designed primarily for a mobile device, Use Express structure, bootstrap, and handlebars for frontend, Nodejs control the backend, Mongodb store the database, early the project was deployed on the Azure, but due to the GFW limits the network speed, user can not open the Website fast, so have to change to AliCloud on HongKong, this server is efficiency, cheaper and doesn’t need to register in the government department, it is an excellent choice for the global eCommerce Platform.
Try to use different functionality to deconstruct the whole project and review the development process again.
1. Structure:
The first and most important part is to use npm install express framework for the eCommerce platform structure.
You can set up middleware to respond to HTTP requests.
The routing table is defined to perform different HTTP request actions.
You can dynamically render HTML pages by passing parameters to the template.
2. Router
You can think of it as a “mini-application”, which can operate middleware and routing methods. Every Express program has a built-in app routing. You can use Router () to create a new router object.
router.post('/dreamList', isLoggedIn, function(req, res, next){ var userId = req.user.id; var user= req.user; var name= req.body.name; var description= req.body.description;
router.post('/search', function(req, res, next){ var replace = req.body.searchItem; var re = new RegExp(replace); Product.find({$or:[{title: re},{description: re}]}, function(err, products){ res.render('shop/search-result', {title: 'search result', products: products, searchItem: replace}); }); });
Javascript receive the data from the router
Js received two variables
1 2
var category = "{{category}}"; var products = {{{json products}}};
Router passed two variables in different way
1 2 3 4 5 6 7 8 9
/* GET second level page. */ router.get('/second-level/:category', function(req, res, next) { category = req.params.category; console.log(category); Product.find({category: category}, function(err, docs){ /*adjust the data sequence to fit the mobil interface by change productChunks to docs */ res.render('shop/second-level', { title: 'Shopping cart', products: docs, category: category }); }); });
It uses a template and an input object to generate HTML or other text formats. Handlebars templates look like a regular text with embedded Handlebars expressions.
Bootstrap is an open-source toolkit for developing with HTML, CSS, and JS. Quickly prototype your ideas or build your entire app with our Sass variables and mixins, responsive grid system, extensive prebuilt components, and powerful plugins built on jQuery.
There are many beauty model, you can directly reference some model in you programm. Like: