I
I
i_surin2016-06-01 11:16:39
JSON
i_surin, 2016-06-01 11:16:39

How to write to JSON using node.js?

Do I understand correctly that in order to save the values ​​sent by the user from the form on the site, you must first save them to a variable:

var event = {
  title: "Конференция",
  date: "сегодня"
};

then convert it to a json string like this:
var str = JSON.stringify(event);
and in the end just save it to a file like this:
var fs = require('fs');
fs.writeFileSync('/some/path/test.txt', str);

Is there a better/easier way to do this, or is this how it's done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vovastradamus, 2016-06-01
@vovastradamus

Have you tried saving to the db? What is this file creation for?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question