Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
100 views
in Technique[技术] by (71.8m points)

node.js - Where to save data in express.js app other than database?

I am showing a link on a page and I want to change that link, by using a form.

where should I save that link and retrieve to render the page other that a database?

*I think involving database for such a small task is not performance efficient.


what I can do is save it in a global variable as a string, so that I can access it and change it.

But is it a good practice to use global variable for such task in production?

question from:https://stackoverflow.com/questions/65932644/where-to-save-data-in-express-js-app-other-than-database

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

OK, now that we know that this is a change that you want to affect all users, then a global or preferably a module-level variable or a property on a module-shared object would be fine.

If you want this change to be persistent and survive a server restart, then you would need to write the change to disk somewhere and have code that reads that setting back in from disk when your server restarts. A simple way to do that might be to read/write it to a file in the JSON format. That gives you simple extensibility to also include other settings in that file.

Your admin form can then just update this variable and trigger a save to disk of all the current settings.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...