Using node.js in a production environment - node.js

I've recently begun hearing a great deal about Node.js. While I understand a few things that it's able to do, namely create a web server, I'm wondering if you could provide me with a solid reasoning behind using this functionality in a production environment.
This article made a solid case for using Node.js as a development tool, essentially stating that it can provide the usability of a backend environment without needing backend experience. I've also heard of many developers using Node.js in production projects (Codepen for example), but I simply don't understand how it can be useful when there are established web servers out there such as a LAMP stack.
I would love to invest the time into learning about Node.js due to its growing popularity, but because I do have a fairly solid backend foundation, I'm curious if it's necessary.
In short, what are some of the most useful aspects of Node.js and why would someone need to use in a production environment?

Perhaps the best answers can come from large companies who are using Node successfully in production.
Why Walmart is using Node.js
How we build eBay's first Node.js application
How LinkedIn used Node.js and HTML5 to build a better, faster app
Scalability is often the big reason. End to end javascript is also a popular answer. Also Node is good at making some potentially complicated "real-time" scenarios almost trivial when using a library like socket.io.
And here is a list of companies using Node with a short blurb on what they use it for.

The main company behind Node.js, Joyent, is tackling this question head-on with their recent roadshow "Node on the Road". They have collected a number of interesting testimonials of why big companies (Dow Jones, Walmart, Yahoo, etc) are using node in production. Check out their videos section for more details.

At my company we use Node in production everywhere. We typically serve the static HTML and JS files using NGINX but smaller apps will use PM2, a Node process manager, to add clustering redundancy and auto restart to a project. PM2 documentation
Example of using PM2 to maximize clusters for your Node app:
pm2 start -i max myNodeServer.js

Related

How to choose the best tech stack for an application

I wanted to start a full stack project, with all the tech stacks in the market i am confused to which one should i pick. I know reactjs in frontend, nodejs and a little bit of django in backend.
First should i use Reactjs or any other frontend framework which is a single page application so all the JS code will execute from frontend or should i use that or Nextjs which does the server side rendering so in the browser we reduce the execution of js. If i stick with Nextjs then suppose i wanted to create a mobile app for my project can i use the nextjs for that or should i shift the code entirely
2)Does backend language really matter, if matters which language should i use and If it doesn’t matter then in nodejs which server framework should i pick(ex: expressjs)
Should I go with server or serverless while creating the api then it does not matter with the framework(because lately I have seen many realtime apps backend code is entirely wrriten by serverless functions using cloud)
4)tell me some of the important things i should use in a realtime app like docker, Kubernetes, load balancer, and any other things you might think this should be present in the full stack app
if you know any blogs or articles about choosing the architecture for ur project comment down.
This is a very opinion and experience based question that cannot be answered as you are asking it (and is technically out of scope in stackoverflow). I will try to help as much as possible anyway.
In general many different stacks are viable and in order to be productive it is more important that you are experienced in what you decide to use. This is because most technologies have pitfalls that can only be avoided by knowing them / experience.
Besides the frontend technologies/frameworks you listed there are many others. Having some experience with React-Native as well, my personal current favorites would be Angular and Flutter (both Google technologies) for web/apps.
It does and it doesn't matter. Without knowing your specific requirements no recommendation can be given though. As a general hint I recommend to use a language that your developers love - There is usually a reason for it. See the 2021 Stackoverflow Developer Survey.
Server vs. Serverless is mostly a business decision and you have to model your costs including hosting / development / maintenance efforts vs. usage models. Another aspect in this decision is time-to-market pressure since Serverless may be a bit faster to finish in some scenarios.
This cannot be answered without knowing the details and requirements of your project. Recommendations could be from hosting a static single web page in a S3 bucket to running your own fleet of (cloud-)-bare-metal clusters or buying a supercomputer.

Node Project & Practice

I am learning Node JS. It had almost learnt 70%. I am very interested in Backend Development but I'm not interested in Frontend development. My question is how do I practice my Node Skills. I only know HTML, CSS in Frontend. How can I make projects in Node JS without knowing Frontend? Or do I need to learn frontend frameworks such as React too to make projects.
You can build an API and use postman to make requests. Start with something simple and keep improving by refactoring your code.
You can work on the API creation part but in my opinion, you must learn one frontend framework it will not only increase your skill sets but also help you to coordinate with frontend easily and take more advantage of it than the projects you will build will be more useful and advanced as well.
You could also focus on implementing some algorithms and data structures starting of with simple ones such as LinkedLists, ArrayLists, sorting algorithms and then move on to (binary) trees and graphs.
These will be required for any programming language to solve (complex) problems and there are many books and internet resources for this. Just search for algorithms and data structures and you'll get plenty. You don't need more than a console application with some simple console.log() statements to implement algorithms - no need for fancy UI.
Last but not least, you should certainly have a look at TypeScript if you want to develop more complex backend applications.
If you really want to do Web Development though it is certainly helpful to have a basic understanding of frontend development or know the basics of common frameworks such as React, Vue, Angular or Svelte.
As others have mentioned for API development you could also just use Postman to send requests.

How to host nodejs application with sockect.io

I have build an chat application using nodejs with mysql database. I have developed on my windows system and it works fine.
Now I want to make it live on a server to check its real time performance, As a beginner I don't know which server hosting should I choose to develop nodejs application, so someone please suggest me a hosting for nodejs application?
If you want something relatively easy to test on, Heroku will provide you with a free instance.
I can also recommend Azure over Amazon for a simple nodejs based app. The main reason is that Azure has a very simplified interface for deploying node apps after a little bit of minor setup. Amazon offers similar capabilities, but the last time I looked at them they aren't quite as simple to get up and running. Again, they're competitive in cost and reliability, this is just a subjective opinion on what I think will be easier for a dev to get up and running without prior experience.
I use Dokku, an open source solution for a Heroku like PaaS. Either of those are great for doing git style deployments. Heroku has better documentation, and doesn't require your own server so I would start with them.
https://www.heroku.com
http://dokku.viewdocs.io/dokku

Which NodeJS frameworks are suitable to build a complete backend for a Nativescript app (JS-based)?

I am now building a native mobile application in Nativescript, leveraging my JS knowledge.
So, I though to switch to some other Nodejs framework.
My app's backend requirements will be:
pure JS
complete backend logic (i.e. controller)
connect to a MongoDB database
RESTful
non-frontend-dependent
non-DOM-dependent
easy-yet-complete to use: should be a framework which gives strong foundations to make a solid and efficient backend for a (relatively) inexperienced backend developer (except for Java basics and experience with pure PHP)
I was considering using my existing knowledge of Meteor but I can't implement any existing experiment of using ddp and websockets in it.
Some of the possibilities I was considering to give a try to:
Loopback
Total.js
Hapi.js
Sail.js
I am fine with any JS-based framework, whether it's NodeJS based or not
I am also open to a REST API solution which exposes Meteor backend, as long as is doesn't require ddp to be usable (it's not very clear to me what are the limits of non using DDP when using Meteor)
Any concrete advice, which would eventually avoid me trying all of them, before discovering they don't work with Nativescript or don't satisfy my requirements?
SailsJs is a wrapper around express.js with many add-ons and shortcuts that eases your life and shortens the code required to write, and it's very much suitable to write RESTful apps.
HAPI and Total, I didn't use them myself, but there are very good reviews about them, but when it comes to Sails, it's the highest in popularity, hence, better tested and used, which leads to a more mature framework over the time.
Loopback is good, but it requires payment at some point of usage, and still Sails is more popular.
Meteor.js is great, but it's not the right tool for that job, and it might take you more effort to make it as an easy to use RESTful framework, not to mention the un-needed memory and processing overhead, which has it's uses, but not in RESTful case. I tried to use it to write RESTful apps but didn't feel the ease and the low memory footprint as I experienced with express and Sails.
Update
Sails has clear and easy to use MVC style, with a command line to generate apis, configure-and-fine-tune-later APIs style, which is very much needed in prototyping and PoC applications, as well as short time to market.
Update 2
Sails ORM supports both SQL and NoSQL DBs, with dozen of supported drivers out there

Decent Node.js library for server workload testing

I'm about to develop a web app so i tought i could test the workload with a single Node client since it can make multiple calls to the server without blocking.
Looking at https://github.com/joyent/node/wiki/modules, in the testing section i foun plenty of frameworks, and my question is if someone can recommend or has heard good things from any of those.
I think this is a perfectly answer question, that's why im asking it here.
Edit:
The idea is to use node on the client side not the server that serves the webapp, so profiling would be out of scope when it comes to decide what node testing framework to use.

Resources