What are the first steps in building a Node.js development - javascript

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.

Related

Service and Controller Layers, Business Logic and Project Structure with Node.js

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.

Real Time API backend and frontend

I'm starting a project to create a front end and back end API that updates in real time.
I was thinking of making something like a Forex "viewer" of sorts using https://www.coinapi.io my only problem is, I want to make the server and everything and have it fetch data from that api, put it in my own DB, and have the frontend update in real time (i.e. a price drops, and it instantly updates without really a refresh).
I'm wondering if something like this is practical. I think its a great idea and I'm super interested in this.
I guess I would use websockets, but I don't know the first thing about that, my experience is with REST API's.
Any ideas/thoughts would be nice.
The frameworks and resources ill be using are:
Bootstrap
Vue.Js
Chart.Js
Node.Js
Express
CoinAPI
MongoDB
Mongoose
I think Express and Socket.io would be a good solution here. They work really well together and you would have crossbrowser checks and a lot of stuff you get with Socket.io out of the box. If you would use your own WebSockets you would have to write all this stuff, which is also a good thing if you know what you are doing.
It can work really well and fast, of course it always depends how well you write your code. But the idea will work fine.
Here you have a beginner friendly tutorial for socket.io:
https://www.youtube.com/watch?v=tHbCkikFfDE
And here is one with MongoDB: https://www.youtube.com/watch?v=8Y6mWhcdSUM

Reactjs and data on server

I'm new to Javascript frameworks and looking for framework for my new projects. Until now i created simple apps using MVC framework Django with Bootstrap frontend. Thanks framework i got everything in one package with best-practice well know. For Javascript i used some jQuery libraries without understanding, just configured with doc help.
When i tried to write some Javascript on my own and found there are big changes in JS world (like ES6, TypeScript) i found it very usefull. When i found JS frameworks, i felt in love.
I have read about frameworks, watched some tutorials. As many other, i found React nice. But what i'm completely missing, is the server part. Especially React tutorials creates components or functions, nice UI, but don't cover what happens with data next. I know that React is ment as "V" in MVC. But what is the best-practice or wide-used extension for server part? Are there tutorials or book to take me further than just creating actions and UI?
Thanks for any links, i just need to point best direction. Or is React ment for just specific project parts and better to look elsewhere?
As you said, yes there are quite a number of tutorials and most of them don't cover how do you deploy node apps on the servers. I'll assume you have some server admin knowledge so I'll skip straight to the meat of the setup.
The Server Setup
Regardless of it being a simple static page, a single page API or a react app, you will need to have Node.js installed on any server you will want it to run. Second you will need a production process manager for Node.js. My personal favourite is PM2. The process manages makes sure your app is always on and restarts it if it goes down for whatever reason. You will also need a reverse proxy server (you need this for security and SEO purposes). Again, a go-to for it is Nginx (it's a competitor of Apache)
Two very good tutorials for setting up your server are
Tut #1
Tut #2
The App Setup
Apart from all the server setup you need to handle routing for your app (what happens when you to go to /blog or /login). A stable standard right now is Express.js. You can do without but then you will need to write a lot of the manual routing by hand in Node.js You will set up Express to server back your Index file and any others you may need.
A good tutorial for configuring your Express for a React app is Video Tut.
He does show a bit more but that is on later videos. You can stop once you get the gist of it.
Advanced Stuff
There's also the matter if you want the JavaScript to be rendered on the server or on the client side. For that you will need to make some more configuration for you app. The video tutorial I linked above should show you how to set that up as well if you are interested.

Resources and information on making a Nodjs application

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,

How to update source codes of a phonegap application from server

I have been developing phonegap applications that need to make updates oftenly. The problem is pushing a new ipa to iTune Store take too long. So, I uploaded the application source codes(minified javascript) to my server and download it from application and "eval" the minified js files. But i feel using eval has limitations and also not the right way. So, can someone tell me the right way to accomplish this.
thank you so much.
I'd love to have something like this as well. You're already ahead of me w/your eval() approach - but I'd have the same concerns as you there. Here's what I'm aware is out there on this topic - hope this helps?
IdeaPress(?)
I just recently caught wind of this one - not sure how feasible but it claims to do exactly what we'd like. I have to say the main site looks a bit flaky but I will definitly be checking this out to see if it's feasible or not.
HockeyApp?
HockeyApp (possibly dead-end now). I thought there used to be a pretty clear solution for PhoneGap devs to integrate the HockeyApp API/feature set with their mobile apps but a recent Google search on this is turning up much less than I would think - so maybe it's a dead end now? http://goo.gl/GQOv5o
org.apache.cordova.file
This requires more work and I haven't pushed far enough yet to see if it truly could be a means of updating the app post-app-store-deployment. But based on what I've read if you're just updating code for your WebView you shouldn't have to worry about App Store rejection or anything. Related tutorial
Testflight App Testing (Apple)
I haven't gotten to play w/this yet but sounds like it could be promising for at least the beta/testing phase of development. I, like you, need a solution for end-users, not app testers, but I'll still be looking into this soon as it might replace me having to maintain my own over-the-air app installs for the best/testing periods.

Categories