I am a newbie/wannabe Full Stack Javascript Developer and I am going through the motions of writing an application, the JS itself isnt extraordinarily difficult, the hard part (at least to me) is the syntax of incorporating all of these dependencies. For instance I am using:
Express
EJS
RethinkDB
PapaParse
passport
socket.io
This is just what I have so far that I know I need, Im sure before I am done I'll need 10 more.
Why are there so little tutorials/documentation on how to use all of these different dependencies together? As someone trying to learn I find it hard to perform the tasks that I need to do without a lot of online looking, searching and whatnot.
At the same time I ask this question I understand that just the simple fact that there are so many makes it hard to do any good learning with my or another exact stack. But that being said there are generalities, like Express and Socket.io with passport are pretty popular I would think. Rethink is a new company but still I find that trying to use EJX with rethink and passport is hard to figure out the syntax.
Does anyone know any real good resources dedicated to the Node platform and this NPM environment? If I were to add Handlebars to this mix I would be even more confused. Obviously I am not a rockstar developer, nor someone who this comes very easily to. I have taken a few very good video courses that explain things well and I understand those concepts but they are few and far between so the gaps between the technologies are huge.
Is there a better way?
I would recommend looking at some better done boilerplates. There a ton of them from github such as hackathon-starter. While they may not have all the best practices and some of them are quite opinionated, it's a good jumping off point.
Another one is to look at open source projects and other well known frameworks at how they set projects up. Laravel is a really good one. Even though it's in PHP, but the app structure and the expressive naming is very easy to read, making a lot of sense. Honestly, I think Laravel is probably one of the best done frameworks for web sites/apps. It's a shame there isn't something quite as comprehensive for Node.
It looks like you are using express for the main library. Take the time to read through their guides, such as the template engine guide. I can't say too much for the other stuff one since I don't use them, but I do use socket.io a lot. If you want your socket to use your express server:
// SERVER
var server = app.listen(3000, function() {
console.log('listening on 3000');
});
// SOCKET
var io = socket.listen(server); // then use 'io' according to socket.io docs
Finally, I would say. Take all of these sources with a grain of salt. While there certainly are best practices, you also have to consider what make sense to you and your projects. Really think through why each framework or boilerplate is structured the way it is. Only then can you think for yourself and find the best solution for you,
Related
I come from a decade of experience with Java EE, SE and Java with Spring. If there's something that was drilled in me by myself and other fellow developers, was how to make use of design patterns, separation of responsibility, separating definition from implementation, interface segregation, etc. Also, we were always worried about testable code (unit testing and integration tests).
When I was learning Java, there wasn't a single book, magazine or website that didn't implemented things with those rules in mind, to the point of boredom. So we always new how things should be done from an architectural point of view when starting new stuff or maintaining code. With time, projects like Spring Boot and JBoss Seams started to give out of the box a basic project layout witch you simply followed to success(or at least you should...).
Now that I delve deep in Node.js, I miss that so much. There seems to be only a handful of people on the web worried about it and trying to teach newcomers how to write good backend code with Node.js.
People teach you how to boot express and put all of your code (database, logging, mailing, error handling and so on) inside an express route.
Of course, when I started learning Java, there was nothing preventing you from using Servlets directly with some JDBC code thrown inside, or even worse, Scriptlet inside JSPs...
I would appreciate so much to know how you for instance implement a service layer, where do you put your business logic? Do you put it in classes or functions that returns other functions? How to write easily testable code by Mocha for instance... Do I really need a controller layer, or can I trust my routes to cover that responsibility?
I'm interested in JavaScript only on the Backend, using Express.js, Socket.io, RabbitMQ, Passport.js, and GraphQL(in the future). Not interested in any rendering engine or template engines, much less JavaScript on the Browser. I'm already very proficient with Sequelizer and Mongoose.
I know the feeling of switching from Java Spring Boot to the Node.js stack. It was confusing for me in the beginning aswell, but with time you find your set of frameworks you like.
I'm probably not qualified enough to answer your entire question, but I can give you some advice of what framework helped me the most after starting with Node.js.
For me, this framework is NestJS.
It's a progressive Node.js framework to build scalable server-sided applications, based on Express.js. It supports a lot of different design patterns, but I personally use a pattern consisting of controllers, services, repositories and providers. You can use multiple different databases obviously.
Nest.js stands out for me, because you don't need any 3rd-party tutorial or documentation, because their own documentation is done really well and has basically all the information you'll ever need. It is really expandable with additional dependencies (most of them are in-house developed and have great documentation aswell).
What also has to be mentioned, is that as a Java-dev you will probably miss OOP if you switch to JavaScript. In Nest.js tough you only develop with TypeScript and overall it gives you a feeling very similar to Java Spring Boot.
I am attempting to develop a 'boardgame' sort-of application, for simplicity sake let's think of monopoly as everybody is familiar with that one. I've read a bit about long-polling and it's implications and this got me confused as it is stated that you need to utilize a framework for it (such as socket.io) anyway, which then uses websockets and such.
Is it possible to avoid this?
I understand that websockets are much better then an ajax request sitting and waiting for a response, but reading up on them made me a bit "scared" of how to implement such a thing. I am not too familiar with node.js (though I'd love to be) mainly because from what I understand it has low hosting support by the providers and is "overly complex to use" or whatnot.
Generally speaking, since we are talking about a boardgame I am not certain that I really need websockets to use realtime client-server communication, because mainly, boardgames are not that intensive on the simultaneous actions and I do not think there would be too many changes to communicate in a short timeframe. I might not be understanding this whole thing correctly so correct me if I am wrong but if the game is slow paced, such as board games usually are, a simple AJAX request should suffice, no? If only I could keep it open in-definitively.
Would it be considered "good practice" to avoid websockets in this case, I mean sure using them is just better then using other things but, comparatively gains are minimal in this case (unless I am not seeing a bigger picture here) for the effort needed to implement it.
P.S. If somebody can recommend a good starting point to how to implement websockets for a simple app such as this one, or direct me to a good "learning material" for node.js that would be awesome as well. I ideally would love to write my backend in js instead of PHP, but I got no clue where to start. I have WAMP running at my machine to test things, IDK how I'd setup node to work on that, or at all.
I have been working with Django as backend and using jQuery for the front end. Now with web pages been so dynamic javascript has started to get more and more complicated and I feel the need of a better, more organized structure there.
I started reading about Backone and it just feels like a backend approach to frontend (since it's an MVC framework). This would make my code more structured but some functionality seems to be overlapping (i.e. models, urls, ...)
I have also read about using backbone with tastypie and django to implement a RESTful environment here. This is very cool since the app would be ready for phone development too.
now my question is how good or bad this architecture is? what pros and cons it has and if there is a simpler way of achieving a DRY client-side code (maybe following some set of rules/good practices would do)
Any personal experience is more than welcome :)
I was in the same situation a few months as you are right now. Of course the number of tutorials, example projects or documentation is very low and most of them very old BUT one tutorial that I came across fishing night and day for help was this http://joshbohde.com/blog/backbonejs-and-django, was and still is at the moment the only one (that I could find) that was reusing Backbone templates into Django templates with the help of some custom template tags.
My personal experience with Django + Backbone was a good one but only lasted a few months, after that I moved to NodeJS + Backbone. I can only say that even though Django/Python is a fast programming language adding Backbone to it will be even faster (user experience) when you think you will only send (to the REST server and back) small pieces of data and not reloading the entire page on every little detail that has changed.
I am a mostly front end JavaScript developer looking to get more into server side development with Node.js. My current level of understanding of Node is decent, ie. I understand what it is, how to install, and basics of getting it running. What I am interested with now is help / advice on what what to do next in order to get larger applications built. What are best practices / frameworks for getting an HTTP server up and running to serve my front end code (HTML, CSS, and JS). I know that there are things like soket.io once you have the app running for communication with the server but it is the first step I am interested in. Also what are best practice for organizing code on the server (separating out front end and back end files on the server). I would also be interested in any advice on getting a database setup and interfacing with it. I think for now I will wait for anything to do with deploying but eventually I will be looking into that.
I know this is a lot and I'm not looking for anyone to answer all this just some help getting pointed in the right direction for the point that I am at right now. I am also not apposed to paying for an material (as long as it is not crazy expensive) so if you have written any books you think that would help someone at my level please point me to it. As always a huge thanks to anyone who thinks they can help me out.
I would recommend you the Express JS framework. It's easy, powerful, and has awesome documentation.
I would definitely use express.js and mongoose to connect to mongodb to save data. I would not start with socketios until you clearly understand how nodejs and its callback mechanisms work. It gets complex and confusing if you do not understand that properly.
Checkout this post.
Looking for a reference nodejs, expressjs & mongodb app to use as template
If you're new to server-side development, I would suggest you start with one of the web frameworks, something such as express.
I would also recommend Underscore.js for writing cleaner more concise JavaScript. If you're planning a frontend of any significant complexity I would throw in Backbone.js to help structure the application. And if you're not sure about server side templating I have had a very positive experience with Jade.
I'm looking to build a rather robust application with NodeJS, however (being new to Node) I'd like some input from more experienced developers.
I've read some good things about flatiron, express / zappa, and others. Sadly it doesn't seem as though anything like http://ruby-toolbox.com exists for Node at the moment to really get a good slice across the spectrum of options.
Two primary things I need to keep in mind is that I'd like to work with CoffeeScript for development and this app will likely have a lot of interaction with a sister Rails app that also accesses the same database.
It seems that some of the projects I've looked at, such as zappa for example, haven't seen some developmental activity for some months.
What frameworks have the most community behind them and meet my hopes? Do you have any frameworks or combinations of libs that you find most useful together?
If you're coming from Rails, I'd recommend taking a look at http://towerjs.org/:
Tower.js is built on top of Node's Connect and Express, modeled after Ruby on Rails. Built for the client and server from the ground up.
Here's the thing: Node.js is less than three years old. It's attracted enormous attention from many exceptionally smart developers, but you can't expect the level of maturity that the Rails ecosystem has. Not everything in the RoR world has a Node.js analogue, and you're going to have to expect to do more low-level coding to get what you need done.
Yes there are a lot of great sounding but now defunct projects out there.
In terms of finding good active projects, this page is a good place to start: https://github.com/joyent/node/wiki/modules
Some of the modules I recommend include
Async
Forever
n
moment
Otherwise, express is virtually universal, and I haven't heard of flatiron or zappa before