Store a single string in Meteor application. Not using database

I need to store a set of string in Meteor APP. I do not want to use database. I want to store it locally. Each app user should be able to store a string. But that string is local to the app only…

How can I do that?

I don’t know what you are trying to do but it sounds like something that could be achieved by a settings.json file. You can define a settings.json like this.

{
  "public": {
     //anyting that you want available to client and server
     "public_key":"some string"
   },
   // anything that you want on the server only.
   "private_key":"some other string"
}

Then when you run your app you can just do meteor --settings settings.json and it will use that. You can have a unique settings.json file for every deployment.

The aim is to let users (people who download the app) store some key access so that they can use it when required.

So a user downalod the app. Opens the app. In the Key section they get to enter some string and the app saves it even if the app is restarted.

I need to achieve this feature :slight_smile:

You probably want to store this data in the browser’s localStorage.

How do I do it? Does it save forever(until the phone is completely erased or the app is remove)? I need the string to be save until the app is not deleted…

Sounds like a perfect job for the database, in a Users collection. Curiously, why do you not want to use the default MongoDB for this?

I would suggest using localStorage if you want the data stored locally. There’s a nice package here which can allow you to this pretty easily!

1 Like

He mentioned he did not want to use a database at all, probably to create a fully client side app.

It should stay in that browser’s locally stored data until it is wiped by the user, not sure what mobile browsers would do differently though.

If the app is fully client side, why bother with Meteor at all? For local games, Meteor is not the optimal solution. Why not use Unity? If he’s using Meteor, he’s likely using the server or some watered down backend anyways, in which case it makes a lot of sense to use the DB for this kind of thing (it’s already there anyways).

If a player’s stats are to be authentic he’s gonna have to use a secure DB at some point.

Sure, using a persistent session (local storage) on the client would do the job too, but then that data is at the mercy of the client!

I don’t know what he’s doing exactly, maybe he prefers Meteor for some other features.

Meteor + Mongo is end goal. But for now not implementing a server side database. This is not a game app. Its more of a information resource app. But I need my end users to save one line of notes. That notes should be presistent on state and should never be gone unless the app is deleted.

window.localStorage.setItem(‘name’, ‘value’);
window.localStorage.getItem(‘name’);

But it’s not reactive like mongo, ReactiveVar or Session would be.

iirc GitHub - okgrow/meteor-persistent-session: Modifies Meteor's Session to store variables in the browser's `localStorage` is reactive.