On Sunday, July 19, 2015 at 11:39:53 AM UTC-4, Christiano da Costa wrote:
>
> Hi guys, I am trying to create a programm wich lets your users create 
> online text files, and share these via URL to others, so that they can make 
> changes on this online document... Does anyone know ow I could be able to 
> generate a URL, linking to this online document??
>

Okay, we're not all guys, but here goes:

you've got three things here: storing documents, identifying them with an 
ID (which can be or be part of a URL), and then the program that maps a URL 
being requested to the thing that loads that part from the database.

The way similar systems do it are one of two ways: A random ID -- like 
gist, they generate a random number, and then use that as the ID for a 
document. The other is that the ID is generated by hashing the document 
itself -- "content addressable storage"; this is what git does internally. 
That gets into complexity when things can change, since changing the 
content changes the hash. For a simple site, go with random number 
generation. It can be a UUID, it can be a random series of bytes expressed 
as hexadecimal (or even a tighter packing if you want shorter IDs)

Then you need a database -- any key-value store works. the filesystem's 
actually a great thing for cases like this. So are databases like leveldb. 
Even networked databases like mongodb or mysql work well.

Then you have to generate URLs -- it can be as simple as concatenation. 
"http://myserver/files/"; 
+ id would be the url of your document.

Then you write something to tie those together. In an express app, that 
might be this:

app.get('/files/:id', function (req, res, next) {
    myDb.get(req.params.id, function (err, data) {
        if (err) return next(err);

        render('viewFile', { file: data });
    });
});

Good luck!

Aria

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/2e12f098-cc68-471a-88f7-471fcf6fe8be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to