I am making a program in Node.js that requires cookies and sessions, but I am not sure how to use them . I tried searching the internet for a solution, but was not able to find one that did not use the express framework (something I want to avoid). How could I use cookies without a framework? What about sessions?
Asked
Active
Viewed 282 times
0
-
Why are you avoiding using libraries that already solve problems? One of the great things about programming with nodejs is the whole NPM eco-system and all the pre-built modules you can build with rather than reinventing yourself. You can certainly set cookies yourself by just setting the correct header in a plain HTTP response, but you will have to study the cookie specification and build properly formatted cookies strings to go in the header. – jfriend00 Apr 25 '16 at 04:37
-
@jfriend00 I wanna learn how to do this stuff without the framework so I have a better understanding of the language as a whole – Arnav Garg Apr 25 '16 at 04:39
-
Then, read the proper specification for the cookie string and write your own function for creating a cookie string and set that as the appropriate header. There's also tons of code out there already that builds cookie strings that you can study too. If you want to learn how to do it yourself, then start doing the work to learn it. FYI, the language (Javascript) has nothing to do with frameworks, so using a framework is of no obstacle to learning the language. – jfriend00 Apr 25 '16 at 04:40
-
Also, the very first Google search hit when I search for this topic is this [Get and Set a Single Cookie with Node.js HTTP Server](http://stackoverflow.com/questions/3393854/get-and-set-a-single-cookie-with-node-js-http-server). Your question does not appear to show proper research and learning before bringing your question here. – jfriend00 Apr 25 '16 at 04:42
-
Also one of the best ways to learn how things work is to use a library that already knows how to do it and then you just trace through its code in the debugger and/or study its code to see exactly how it works. I've used that techniques many times to learn how things work. – jfriend00 Apr 25 '16 at 04:46
-
Info about sessions: http://stackoverflow.com/questions/5522020/how-do-sessions-work-in-express-js-with-node-js?rq=1 – jfriend00 Apr 25 '16 at 04:56