Why in the name of god do people keep using node.js for web servers? Serious question

Why in the name of god do people keep using node.js for web servers? Serious question.

Other urls found in this thread:

github.com/libuv/libuv
twitter.com/NSFWRedditImage

For the same reason people use MongoDB as database: They are retards.

It's the hip thing to do

"Because they are stupid" or "Because it is better" is the average 4channer's answer to everything.

Not helpful, user.

node.js is (so far) the worst decision of the 21st century.

Absolutely not. Just wait for the sandnigger bombings that are about to come

usually they have no fuckin clue one way or the other but like to seem smart. It's a youthful thing.

socket.io/websockets is the only legit reason I can think of.

Although those can be done with php etc nowadays too so...

I use node.js for all my general purpose scripting needs. Is there a better way to do it, there's just a library for everything.

Why not PHP, Python, Go, etc? I understand the arguments for the advantages node.js offers in terms of concurrent connections and polling and so on but why would you use it instead of something better and faster?

Webservers are mainly IO intensive (not cpu), so cpu performance isn't that important, and Node has great IO facilities.

I've had a toy project in it. Got unwieldy soon because I'm not good at Javascript, and it bit me in the ass. I have a problem with non typed languages.
It has fast code-to-live cycle, even tho maintenance is hell.

It's as good as anything else for CRUD apps, IO heavy apps, and a random microservice.

It has had the merit of pushing non-blocking IO to the mainstream, which, while not being the panacea, it's nice to have in any language.

Because true web artisans need to go through monthly interations of "The Wheel: Reinvented With a Cooler Logo" to stay hip.

PHP's alright I guess, but Node's package management is way better. Not a huge fan of Python's whitespace as formatting. Looked into Go a bit, but JS is approachable and has a larger package base.

folks going for scripting don't tend to chase after speed. Node.js doesn't noticeably faster or slower in this case.

If you're mostly interfacing with web stuff (ie doing api requests) having the data come back as json makes life much easier than dealing with some of the pain points converting to dictionaries in python.

Concurrent stuff is rather relevant for the above.

function pointers are nice way to do some things and make code unreadable.

node.js really sucks for anything sequential and then you end up wasting time finding those bugs.

Node is really nice for doing prototype REST apis. Stick it behind a NGINX proxy and it's not bad. No clue how that scales with thousands of hits per minute - apparently pretty good though.

Nodes weak point is ORM's and sequential stuff. Unless you're working with mongodb (which is really hard to do right and easy to do very wrong) there isn't any real /good/ mature ORM's

PHP is just gross and I don't know Go so I can't really speak on that.

Rails is good, it's ORM, Active Record, is the best ORM I've ever seen, that thing is genius

you will get used to Python and its whitespace after your first project probably

because it's fuck simple to prototype a rest API for proof of concepts, once you get the cash then build it in a real language.

It allows companies to Jew their front end devs into also writing backend code for the same wage.

This.

Not just NPM either but the way that packages are loaded. It makes it much easier to work with different versions of a package if you need to.

Also Node is asynchronous and has a lot of people working on it trying to figure out the "best" way to do things (note that promises are no longer part of node because other ways are all around better).

Node also makes it easier to do stuff like running multiple servers.

That said, just because you use Node doesn't mean you aren't allowed to use other languages. Some languages are better than others for different things. I'm currently working on a project that uses
>an nginx reverse proxy
>an apache server + mysql + php (LAMP)
>node servers + mongoDB
Different parts of the project are handled by different pieces of software.

>node.js really sucks for anything sequential and then you end up wasting time finding those bugs.

I'm gonna assume that for that bullet-point, NodeJS is a synonym for JavaScript.

What makes JavaScript bad for sequential code?

yeah but I'm already used to and prefer C-style, so it's like why bother. Plus python is still on that 2.7 / 3 schism.

Could be easy to manage after initial development. I prefer rails

It's faster than php or ruby but faster to prototype with than Java or C#. I can also show a front end dev some server code so they can understand what is actually going on.

JavaScript and Node are single-threaded, meaning that you literally can't block in a function without halting your whole webserver.
Since it's so costly to block, you use asynchronous IO methods with callbacks. Callbacks yield some ugly, unwieldy and unmaintanable code that's difficult to reason about (at least to this humble JS novice).

> PHP is just gross
Not a PHP advocate, but as far as dynamic languages go, I'd much rather use one with sane scoping rules, proper encapsulation and type hinting than one without those things.

ORM is a meme. Tables of a properly designed, normalized database almost never translate directly to domain objects. Real men write their own data mappers.

I assume that everybody is familiar with the slang, sorry.

"to block" means to use an IO method which halts execution until the IO call has returned. It's not a problem in a traditional threaded model, but JS/Node is single-threaded.

99% of applications aren't performance-critical.

Why ship in a six months, when you can ship in two?

But yeah, move along, real men passing though

Basically it never waits.

var output = null;
$.ajax('/something', function(result){ output = result });
console.log(output);

----

console.log(output) will run before the ajax call finishes. (usually, sometimes when you're doing local development these issues don't show up because the latency is so low - not a fun bug to track down...)

So you end up doing stuff like promises, passing in callbacks, and a whole lot of other stuff.

I guess it's good if your backend has actually some stuff to process and you're too retarded to write decent multithreaded Java or C#.

I'm not that guy, but

>NodeJS is a synonym for JavaScript.

Node.js is an implementation of JavaScript that can be run stand-alone (without a browser). It has a REPL and a number of 'core modules' that add the functionality of a normal scripting language (stuff like file system stuff, network IO, timers, operating system stuff, loading C/C++ code, etc..) as well as more specific functionality like stream editing and creating web servers (part of network IO).

There is also a package manager for Node packaged modules called NPM. Said packages aren't strictly javascript code (you can have stuff like linters and stuff as well) and they aren't strictly meant for use in Node (stuff can run browser side). The main thing of interest is that the community is ridiculously active and the package manager has git integration.

tl;dr: Node.js = JavaScript + a bunch of libraries + a runtime environment

>What makes JavaScript bad for sequential code?
I'm not sure if it's a big deal for JavaScript but Node is specifically designed to be asynchronous (many built-in functions are asynchronous and some, but not all, have a synchronous version as well). Often times synchronous operation is kind of an afterthought in many modules. This can be difficult for people who aren't used to asynchronous code or to using functions as first class citizens. I come from a Haskell background so it's actually fairly natural to pass around callback functions.

>
>ORM is a meme. Tables of a properly designed, normalized database almost never translate directly to domain objects. Real men write their own data mappers.

Real men don't waste time writing data mappers because time is money.

I still don't see how that's a JS-only thing.

If you use a callback like that, isn't the code running concurrently, being executed in two different places at the same time?

How is that fundamentally different from another language just creating a green-thread or an OS thread and executing heavy stuff in them?

Or is it because there's no way to wait() on a deferred function in JS?

>I guess it's good if your backend has actually some stuff to process and you're too retarded to write decent multithreaded Java or C#.
>decent multithreaded Java or C#.
>multithreaded Java or C#.
>decent
>Java or C#.
>decent
fucking lol

Node.js uses libuv. That's way faster and better than any garbage you could ever write in those shit languages.
github.com/libuv/libuv

Javascript is single-threaded but uses a queuing method for asynchronous callbacks.

Cenceptually there's little diffrence.

In practice, in other languages you need to go an extra lenght to make an async IO call, while in JS IO calls are async by default (often with no alternative to make it sync, since you'll be blocking the whole app).

It's a big gotcha for someone having a bite of JS

>whitespace as formatting
Whitespace is literally formatting in every language, user. Python is one of the only languages in which whitespace isn't just formatting.

Node.js is much more scalable than the apache webserver, in the sense that it can deal a lot better with a large number of concurrent connections.
Node.js isn't a webserver though, people should use nginx instead. Node.js is mostly handy if you need a custom way of handling things, or something that can deal with websockets properly.

This all seems insane and I don't think I can feel bad for not even wanting to attempt to understand it.

because is good enough for most things.

node itself is written in C++, the javascript functions you call in node are actually wrappers of C++ functions

AHAH OMG EPIC LULZ! UPVOTE UPVOTE GOLD 4 U

>Nodes weak point is ORM's and sequential stuff.
ORMs are only needed when working with relational databases, node works better with nosql databases so it doenst need ORMs as nosql usually uses key/value pairs like what JSON provides

Yeah, the no-ORM is a weaksauce argument. Node doesn't even drivers for SQL databases anyway, because the devs only use NoSQL and NoIntegrity databases.

npm has some pretty solid ORM libraries though, doesn't it?

like i agree that you're kind of doing it wrong if you're using node js with sql, but if you really want you can do it, and you're hardly up shit creek.