From the course: Node.js: Design Patterns

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Implementing an adapter

Implementing an adapter - Node.js Tutorial

From the course: Node.js: Design Patterns

Start my 1-month free trial

Implementing an adapter

- [Instructor] In the last lesson, we defined the adapter pattern and we looked at a case in JavaScript where an adapter might be helpful. Here we have some code inside of the index.js file inside of our exercise files under chapter three lesson two within the start folder that uses the local storage API. This API is only available in the browser, and it's not available in node JS. But we can use this exact same code if we create an adapter for this API. So what we're going to do is require a new file that will create called localStorage. And what we want to do with our local storage file is create the exact same interface that the browser API has for local storage. So let's go ahead and create a brand new file. And within our local storage file, we're going to create a class called localStorage. We're going to make sure we export a new instance of localStorage. So what we need to do in this class is we need to provide the same interface that we have in the browser local storage. Or…

Contents