Check out a free preview of the full API Design in Node.js, v3 course:
The "Node.js for APIs" Lesson is part of the full, API Design in Node.js, v3 course featured in this preview video. Here's what you'd learn in this lesson:

Scott discusses which types are APIs are best when using Node.js.

Get Unlimited Access Now

Transcript from the "Node.js for APIs" Lesson

>> Scott Moss: So now we're gonna talk about Node.js and how it works with APIs. So basically, Node.js is built for high concurrent APIs that are not CPU intensive. So what exactly does that mean? Well one, Node.js is JavaScript, so it's async and it's event driven. That allows it to take on a lot of high concurrent requests.

[00:00:23] Because it is a bit driven when requests do come in, they get sent off to the bit loop to be handled asynchronously, so that way you can register more requests so it is very high concurrent. But because it is single threaded, It's not gonna be great for CPU intensive things.

[00:00:41] So you're not gonna be doing things like machine learning and that type of stuff, you could and you can optimize like I put here, you can definitely optimize it for it not be single threaded. But, you're probably better off using something like Python or something like that to do some big CPU intensive operations.

[00:01:01] When you do keep, like I said when you keep node async, it can handle a lot of concurrent requests. And the key here is that you do keep it async. You could block node. For instance if you put a while loop that takes forever to execute, nobody's gonna be able to register anymore requests on your api.

[00:01:17] Because you're still in a while loop on request number one. And you have like 100 requests per second coming in. They're not gonna be registered because you're blocking JavaScript with this while loop, cuz it's a single thread. So you gotta be careful of how you actually, or what you actually do in node, and try to keep everything asynchronous.

[00:01:37] And like I said, it's not great for CPU intensive work, so although yes, there's tensored flow.js and all this stuff in JavaScript, you can totally do it in node. And because it's getting better and better, and spitting up a new CPU at a new machine in a cloud is like basically free now, you can totally do it.

[00:01:53] But it is definitely not designed for that. And there might be better tools. Really depends on what you want to do. I mean, nowadays you can do machine learning in a browser. I think they have TensorFlow in a browser now, so. Who am I to say you can't do it, but I'm just letting you know what it was built for.

[00:02:07] What it's intended for. Yeah, and there's just a lot of open source stuff out there. Literally, there is so many open source tools for APIs and node, it's kinda ridiculous. We're just gonna be talking about one, Express. But there's so many of them. Most of them are actually based off Express, but there is a lot of them, and that's just true.

[00:02:26] With anything in node, there's just a lot of packages and a lot of libraries, but when it comes to APIs, there is this overflow amount.