I have a little website in node.js, when a people want to sign up we call a function (a external file) here the part where i write the JSON :
{
nouveauMembre
As Chris G has already posted in the comment, you have written query.pseudo".json"
instead of query.pseudo+".json"
- you should get a syntax error telling you that.
But I see some more serious issues with your code.
First of all you will get into trouble using writeFileSync
(or readFileSync
or any other -Sync
functions) as soon as you get more concurrent connections. Those are blocking calls and should be used only on the first tick of the event loop. For serving requests you should be using only the asynchronous version (without Sync
in their name).
Second of all, you have a serious security issue where anyone could write to any place in your file system by using a pseudonym containing slashes or double dots.
Third, your are storing user passwords in plain text which is unacceptable and may cause you legal troubles in many cases.
You seem to be implementing your own database but you have not considered:
You can either try to fix all of those issues to make your system secure (by sanitizing the input data) and performant (by not using the blocking functions) and fix some more minor issues with it, or you can use a working and tested solution to store your data.
If you don't want to use a stand-alone database like MongoDB, RethinkDB or PostgreSQL or anything like that and you want all your data stored in files on your file system, then you can use something like those:
and many others.
I wouldn't recommend building a database management system, which is exactly what you're doing here, to anyone who is not experienced with that.