O'Reilly logo

Continuous Integration, Delivery, and Deployment by Sander Rossel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Moving the Shopping Cart Module

I want to do one last thing. The shopping cart controller is mighty handy. No doubt we want to reuse this functionality in Node.js to create invoices. Luckily, we have kind of future proofed our frontend scripts with Browserify already, so we can simply create a module and use it on both the frontend and backend.

Create a new file in your scripts folder and name it order.js. In it goes most of the code from the shopping-cart.js file:

module.exports = (function () {   var Order = function () {      this.lines = [];   };   Order.prototype.removeLine = function (line) {      this.lines.splice(this.lines.indexOf(line), 1);   };   [...]   return {      Order: Order,      Line: Line   };})();

Since we are not working on the $scope object anymore, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required