This course has been updated! We now recommend you take the API Design in Node.js, v4 course.

Check out a free preview of the full API Design in Node.js (using Express & Mongo) course:
The "Q&A Part 2" Lesson is part of the full, API Design in Node.js (using Express & Mongo) course featured in this preview video. Here's what you'd learn in this lesson:

Scott continues the final Q&A with some ways to scale the MEAN stack, recommended resources for beginners, and NPM modules for interfacing with other databases.

Get Unlimited Access Now

Transcript from the "Q&A Part 2" Lesson

>> [MUSIC]

>> Speaker 1: This kind of goes back to where I think we were talking about any authenticated user can change anything in the application.
>> Speaker 2: Right, right.
>> Speaker 1: But somebody is saying that you can't update other users in this app anyways. Because the request.user object from app.params ID gets overwritten by auth get fresh user

>> Speaker 2: Auth, let's see. Yeah, actually it does.
>> Speaker 1: And then so he's just saying that's not intentional.
>> Speaker 2: Yeah.
>> Speaker 1: So, how can you avoid loading the request like this?
>> Speaker 2: Make a different object name, not user. Call it reg.something else, You just have to namespace it, I guess.

[00:00:42] But yeah, that is unintentional, I didn't even realize until he just said it. But yeah that would definitely happen, you would just have to give a different name space, just not put everything on the user.
>> Speaker 1: Another question, just general, what are some ways to scale the mean stack?

>> Speaker 2: Well, you can just throw more money at it, if it's on Heroku. [LAUGH] scale of the Dynos. Here, I'll show you, hold on. This is the easiest way to scale, let's see, where is it at? Where's that button? There we go. So, if I come over here, and I click this button.

>> Speaker 1: [LAUGH]
>> Speaker 2: That's probably the easiest way to scale, no you don't wanna do that. So, as far as horizontally or vertically scaling, the easiest way is definitely clicking this button.
>> Speaker 1: [LAUGH]
>> Speaker 2: [LAUGH]
>> Speaker 1: [LAUGH]
>> Speaker 2: That's if you don't mind spending the money. But I mean there are ways, as far as getting you have huge data sets, right?

[00:01:43] So, you start getting replicated sets. So, you start replicating the database and doing that stuff every night, and then you might start charting the database on different indices. So, lets say we have a users table and we start charting on alphabetical order from A through D, we're gonna take this and stick it over here.

[00:02:02] And we're gonna grab these and stick these over here. So we're running them on different machines. Right, and then when we query it'll go to the appropriate one. So, that's one way, another way is just load up more instances. So, you can throw more money into it, and beef up stuff vertically.

[00:02:17] Or you can just like, I'll let's keep these lower level mid-tier ones and just go out horizontally. Just buy more of those. So, I'm definitely no expert on that. But from my experience because I am not a devopps person. I just throw money at it. So, I don't really have a better answer to that.

>> Speaker 1: Another question was
>> Speaker 1: Let's see, what would you recommend for a beginner to read up on and master some of this material?
>> Speaker 2: Yeah, so there's this really good blog that I like to read. It makes sense to me. So if reading is your thing, if you wanted to read, then I would definitely recommend Scotch IO.

[00:03:07] This stuff has some, I mean look, node and MongoDB on Heroku, that's what we just did today, it was just published. So this is good blog posts. If I do read blog posts, it's mostly stuff on here, or random people's blog. This one's really good, they love Mean Stack.

[00:03:20] They wrote a book on Mean Stack so they know it pretty well. So, if reading was your thing and that's what you needed to do, I would do this.
>> Speaker 2: Any other questions?
>> Speaker 1: [COUGH] Any NPM modules you can recommend for interfacing with my SQL?
>> Speaker 2: [SOUND] Sequelize is good.

[00:03:46] There's a better one, though, than Sequelize. [SOUND] Let me see. Before I recommend it, let me make sure it works for SQL and not just Postgres. Bookshelf SQL. Let's see. Yeah, I think it's Bookshelf. Yeah, so, Bookshelf is probably the most popular one. And SQLize is probably the next best one.

[00:04:18] If you're familiar with Backbone then Bookshelf will feel like home, it's made by like the same people. It looks backbone too. Actually it looks different, they updated it a little bit, but it still kind of looks like Backbone. But, yeah, that's the most popular one, then SQLize.
>> Speaker 1: Do any of those handle MS SQL?

>> Speaker 2: I have no idea.
>> Speaker 1: SQL has js host of it.
>> Speaker 2: This one does it. It says, Postgres, MySQL, and SQLite3. So
>> Speaker 2: Anything else? I'm kind of parsing through all of them here quick. So here's a good repo to go look at some awesome node stuff.

[00:04:58] It's literally called node awesome. If you go here, it's just a read me of awesome things in node.
>> Speaker 2: So, if you ever need something awesome just go read this thing, I really need something really nice for the file system. Here we go, it's all the stuff you need.

[00:05:16] What about build tools, yeah that's it. So and the guy who made this is like I think he's a group of people, this guy, but he's very well known. So, iIf he keeps that list updated, I mean, two days ago with 7000 stars. I'm sure it's a good list.

[00:05:34] 7000 starts for a readme is ridiculous. Yep?
>> Speaker 1: What do you think about Elasticsearch and Cabana?
>> Speaker 2: I don't know what cabana is, but Elasticsearch is awesome. I use it a lot. Most apps these days need some type of functionality like Elasticsearch, and it's pretty cool cuz it's open source.

[00:05:57] So, you can post it yourself and then there's tons of Elasticsearch Azure service platforms out there. Heroku has some of them. So, if search, if you need that, you know, that real time search. You need the power of Google in your app then, yeah, logic search is awesome.

[00:06:12] You just throw stuff at it and get it later. I really like it. It's pretty simple to use. I actually tried to deploy my own hosting on it before. Didn't have too much luck, but then again that was a couple years ago before I knew what I was doing, so I might try it again.

[00:06:23] So yeah, I recommend Elasticsearch, cannot recommend another one.
>> Speaker 2: Anything else here?
>> Speaker 1: Any thoughts on clustering Node?
>> Speaker 2: Yeah, you can cluster node, but you have to in node if you wanted to use clusters. You would just MPM install, or I'm sorry you would require the cluster module which is actually brand new.

[00:06:56] All right we'll go. Well it's not brand new, but, let's see. There we go. Stability to, it's unstable according to these docs. Maybe these docs are out of date. But yeah you can use the cluster module. I don't know like, I'm like kind of biased, I'm not biased but I'm like kind of neutral on this because I like the fact that node is running on one thread and it's evented I/O.

[00:07:21] At the same time, it's like, I wish I had more power, access more of these cores. So, the cluster allows you to do that but then again, you have to manage that stuff. Stuff gets kind of gets out the wok if you're not familiar with working on multithreaded platforms, especially if the platforms are multithreaded and asynchrous at the same time.

[00:07:41] I mean you can run into some trouble. We start having threads being blocked, by you doing a wild loop that never ends. You know what I mean? And you're just stuck, I'm kind of unsure about this. I never really used it in production. I've built some stuff with it just to learn about it, but I don't really have any strong opinions for or against it.

[00:08:05] But if I had to do something that was like CPU insensitive, I probably wouldn't just use node to be honest, I always use like Python or Go. Something that was like heavy, like I'm not gonna build like some sensitive analysis machine learning algorithm in node. It probably would work, but it'll be really hard and I'd be really, really good at math, so I'll just go somewhere else.

>> Speaker 1: They want just a quick recap on module x, verses export. Just the elevator pitch.
>> Speaker 2: So module.exports is like, I'm going to export this entire file. Module exports is like nothing else is going to be exported, except for the thing to the right of this equal sign or module.exports.

[00:08:53] You can think of it like this, module is like the file, exports is an object and you can put whatever you want on exports. And if you use exports by itself, it's still just putting whatever you want on exports. But when you require it, exports just gets attached to module.

[00:09:13] So, at the end it's still just module, it's just exports is like I want to export many things. So, when I require it, I'll have an object with all those properties on it. Module.exports is like, whatever I require is gonna be whatever module the exports was. It's only gonna be that one thing.