This course has been updated! We now recommend you take the AWS for Front-End Engineers (ft. S3, Cloudfront & Route 53) course.

Check out a free preview of the full Zero to Production Node.js on Amazon Web Services course:
The "Exercise 2 Solution" Lesson is part of the full, Zero to Production Node.js on Amazon Web Services course featured in this preview video. Here's what you'd learn in this lesson:

Kevin walks through the solution to Exercise 2.

Get Unlimited Access Now

Transcript from the "Exercise 2 Solution" Lesson

>> [MUSIC]

>> Kevin Whinnery: I think we'll go ahead and go over some of the results. It looks like we had folks step up to the challenge, once again, with some solutions that are looking correct, like something we can ship. The first one I wanted to check was the pull request from Lucas, here in the room, that added the uglify configuration to the application.

[00:00:32] So what Lucas did here, bump that up a little bit. So what Lucas did in the grunt file is he added a new configuration for the uglify task. He created a target called my_target. Not a super descriptive name, but I think I think it does work. We can probably follow on and figure out something for that.

[00:00:55] I think in this case, maybe like dist or something like that would be appropriate. But in this case, we are gonna be taking app.js and writing it out to app.js. Now in this case, I probably would have added like a .min.js or something to the to the end, to sort of specify it.

[00:01:18] That it would be the minified version rather than the regular uncompressed version. But that's generally what we're looking for. We need this file, which is public/app.js, to be uglified. And in this case, we're gonna output it to the same file. Probably, we'd wanna do a different file, but that's generally what we need.

[00:01:42] And then we also have the uglify task loaded in from grunt-contrib, which is exactly what we need. And then we also add in the uglify task to the collect_static command. Which was the desired enhancement that we had to the project. And we also required the 2.0 version of uglify, which, I think, sounds fine.

[00:02:12] And actually here I just pulled down Lucas' branch locally so I could check it out. So if we run grunt collect_static,
>> Kevin Whinnery: That's gonna run our browserify task. And then we also see that we ran the uglify task successfully. And then if we look at our public directory, which is the desired output, we definitely have some uglified JavaScript in there.

[00:02:45] So a couple bits to tweak, but that definitely works. So like, [APPLAUSE] excellent work, Lucas, very nicely done.
>> Speaker 2: How did he know to get the version 2.0.-whatever of uglify?
>> Kevin Whinnery: My guess is that what he did was do npminstall--save grunt-contrib uglify. Which will add the latest stable version of that track folder to npm, your package.json, excuse me.

[00:03:14] So that's totally good, I think, well, I may make a few minor modifications. And push it up before I push it into master, but that's what we need. So you definitely get the free taco there. That's a lie, there are no free tacos, sorry. I probably should have brought tacos.

>> [LAUGH]
>> Kevin Whinnery: That would have been a good idea. All right, so let's take a look at one of the other solutions that we had. So that was what we were looking for, for uglify. And then we needed a npm script to look,
>> Kevin Whinnery: To actually run the migrations.

>> Kevin Whinnery: So we have one pull request for that, so let's let's take a look. All right, so this pull request also includes the uglify solution, which is just fine. Usually we wanna keep one pull request to one issue, but I won't wrist-slap very hard for that here. I appreciate-

>> Speaker 3: [INAUDIBLE]
>> Kevin Whinnery: What's that?
>> Speaker 3: It didn't originally. I think he just forgot to branch.
>> Kevin Whinnery: It's okay, that's just fine. All right, so the key bit that we have here is the migrate command was added here. Maybe it'll be a little bit easier if we actually view the file.

[00:04:35] So we have this prestart command. And that's actually gonna be executed on our Elastic Beanstalk instance before the server process is started to run any pending database migrations. But we also wanted to have a custom script. Because that prestart could eventually do other things besides just run the migrations.

[00:04:59] So we created another task called migrate, which also used the local version of sequelize to run the migrations. So just for the sake of expedience, I'll copy that just to see what that's gonna do.
>> Kevin Whinnery: And the thing I was hinting at in the comments, if you were kind of reading through that thread, is that the way that you invoke like nonstandard npm scripts is slightly different than for those that you would that run otherwise.

[00:05:34] So if I say like npm start,
>> Kevin Whinnery: That's gonna run the migrations. And it's going to start up my development server process on port 3000. So npm already knows how to npm start. But if I say npm migrate, it's gonna say, what? I don't know, I don't know what a migrate is.

[00:05:59] So it's not one of the sort of built-in commands that npm knows about. So rather than saying npm migrate, I'm gonna say npm run-script,
>> Kevin Whinnery: migrate, and then that's going to run my migrations using the built-in sequelize module. So if you add commands to the package.json that aren't part of the known set of npm commands, you do have to add in that extra run-script prefix before you could run those commands.

[00:06:33] So that was the bit that I wanted to point out there.