From the course: Building APIs with LoopBack

Unlock the full course today

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

Modifying the in-memory data source to save data

Modifying the in-memory data source to save data - Node.js Tutorial

From the course: Building APIs with LoopBack

Start my 1-month free trial

Modifying the in-memory data source to save data

- [Instructor] Okay, so if you don't want to use a real database, and like how quick and easy the memory data source is, I've got a tip to share with you. A reminder, though, do not ever use this in production. It may be tempting, especially with the tip I'm going to show, but you should never go live with it. While testing or showing to a client, it's okay, but you'll want to switch at some point. Alright, so if you remember, every time you restart LoopBack, you lose all the data you created. While testing, that could be annoying. Luckily, there's a neat little trick. First, we'll open up datasources.json again. If I add one little property to the data source, the memory data source will actually be a file-based one. All I need to do is add a file key with a name. I'll do file, and we'll call it mydata.json. The actual filename doesn't really matter, but you'll want something you can remember. Now, let's restart the app. Alright, now that it's up and running, let's test this out. I'm…

Contents