First commit… finally!
It took me waay longer than I expected, to start with the project. I’ll touch the surface of the reasons in another post, but what I’d like to simply report you the progress I’m at with the Byrd.
In my recent post, of #GetNoticed series, I said I’m gonna be starting out with front-end, because I’m not too sure about backend technology I’m planning to go with. Well, alot has changed, and since I’m not having much of free time, I made final decision; I’m going with the stack I’m the most familiar with - Node.js, MongoDB, React/Redux.
Although, as this project has to be websocket based (live chat), I’m not too sure about communication between the backend and the chat. In other words, I’ve recently heard about Firebase, I was recently building a simple app based on FB and you know what? That seems to be even easier than with WSS. I’m still arguing with myself on what I should base my chat on.
But let’s dive into what I got so far. That’s not much, I got to say. But that’s good start. So far I have chosen the file structure, I’ve set Express app, set babel, and whole user authentication; routes, middlewares and mongoose model. It’s based on JWT btw. That’s not a lot, but definitely I am quite satisfied, considering the fact I spent on it just few hours. I got it well documented, written unit tests.
As i mentioned above, I use babel for my app. You may ask: “why, what’s the point, since Node 7 supports ES6 by default”. Well, that’s not actually true. Yes, i does support some or maybe even most of it’s functionality, but not all of it. Great example is import statement, which is one of the most exciting part of ES6. It not implemented. Why? I don’t know, I didn’t dive into it. But babel deals with it, by compiling the code to regular ES5, and makes import, a CommonJS way (require()). You may think that’s missing with the point. You’d be right with your words. I completely agree, it’s not real import statement. But once you try it — you don’t wanna go back to regular require() statement, and you anyway, are preparing yourself for new, incoming functionality. Why shouldn’t you use it if there’s such option now?
JSON Web Tokens
I will not dive into what JWTs are, as I’ve quite widely covered the concept and how are they used in real life applications on another thread. If you’re interested in what they are, and if you would even need to use then, click HERE!, and find out a bit more!
But why I decided to use stateless session in the Byrd? Well, that’s pretty simple. I’m planning to separate the dashboard, from the homepage — by subdomain. As you’re aware, cookies aren’t cross-domain shared, so the only valid way, to keep UX on the acceptable level — is to make That way, I’ll be able to to keep users signed-in, when visit the blog or the newsfeed. They’ll be more likely to comment, and share their thoughts, when they’ll be logged in automatically.
I used mocha and chai for unit testing. The problem I came up is… I got no idea what’s the valid way of unit testing mongoose models. I tried to make a mockup with sinon, but it just simulated a result, as that’d be JSON format. Which we all know, it’s not. This wouldn’t let me to make use of any methods I created, and basically — wouldn’t bring me any benefit, from using it. So I went without any mongoose mockup layer, I decided to make regular connection, to the test database, which would be wiped after all tests are completed. That’s quite slow way of testing, that’s for sure, but I haven’t found a better one. If you have any ideas — please share with me!