Loading
Lesson 39
Courses / Software School Cuts
Generate NPM Project and Install ExpressJS

The lecture gives a brief overview of what Nodejs is.

Then you get introduced to the Express library.

After that, you learn how to generate an NPM project with the creation of a package dot json file.

The lecture shows you how to install the express package from the Node Package Manager (NPM) registry.

You learn that third-party packages are installed in a directory called node_modules. Dependencies are specified in the manifest file called package followed by the extension json.

Somebody has a question about NPM not being recognized. Make sure to install Node from the website nodejs dot org. It usually comes bundled with the NPM command as well.

Somebody else asks how to verify the library express was actually installed.

Summary

Summary of the Transcript on Express.js

In the discussion, the speaker introduces Express.js, a library used for developing back-end applications in Node.js. Here’s a simplified breakdown of the key points:

Overview of Web Development

  • Front-End Technologies: HTML, CSS, and JavaScript are used to create interactive websites.
  • Back-End Role: The back end acts as an intermediary between the client (browser) and the data, typically stored in a database.
  • Choice of Languages: Various programming languages can be used for back-end development; JavaScript has become popular thanks to Node.js.

What is Node.js?

  • Introduction: Node.js allows JavaScript to be run on the server side, extending its usage beyond client-side programming in browsers.
  • Functionality: It enables developers familiar with JavaScript to also write server-side code.

Express.js Explanation

  • Purpose: Express.js simplifies the process of building web servers with Node.js, avoiding the complexity of using the lower-level HTTP module directly.
  • Convenience: It provides a set of tools and middleware for easier handling of requests and responses.

Getting Started with Express.js

  1. Creating a Project Directory:

    • Use the command MKDIR express to create a project folder.
    • Change into the directory using cd express.
  2. Initializing a Node Project:

    • Run NPM init to create a package.json file which defines the project.
    • Follow prompts to set up defaults.
  3. Installing Express:

    • Execute NPM install express to add Express.js to your project.
    • This command creates a node_modules directory where Express and its dependencies are stored.
  4. Verification:

    • Check package.json to confirm Express is listed under dependencies.
    • Inspect the node_modules folder to see the Express directory and its source code.

Common Questions

  • Node.js Installation: Ensure Node.js is installed to access NPM. If issues arise (like NPM not being recognized), troubleshooting installation will be necessary.
  • Checking Installed Modules: Verify if Express or any modules are installed by checking for their presence in the node_modules directory and in package.json.

This guide provides a foundational understanding of how to set up and begin using Express.js for back-end web development with Node.js.

Video Transcript

Okay, so today I'll talk about Express. So today if you have web development, right, you have HTML, CSS, JavaScript for the front end, and you can make like a website that's kind of interactive at some JavaScript. Yes, it's very pretty with CSS. But you know, where does that, all that data goes? How is it stored? You know, it's storing the database somewhere in what is called the back end. But the back end is a program to act as an intermediate between the browser, the client, that people accessing the website or a web app, and the data. And that program can be built in any programming language today pretty much. So different companies use different languages for the back end server. A very popular choice today is writing a back end in the JavaScript programming language, which is the same as the front end. Traditionally that was not possible, but it has been made possible with the advent of Node.js. Node.js, put simply is just JavaScript, but on the server side. JavaScript, the language originated from client-side programming in the browser. And then somebody had the idea, okay, why not use that for other things outside the browser? So they created Node.js. Okay, so pretty much server-side JavaScript. So if you can write client-side, you can write server-side the same way, the same language. Now, writing that like a web server to serve pages or requests from users might be a tedious task if written in the very raw or lower level HTTP module from the Node.js. So express this library was written and pretty much it makes it easier for us to build a web server with Node.js programming language. Okay, instead of us having to type everything from scratch, it already wrote the code for us, somebody wrote the code for us and put it in a package that's called express.js. And that's what we're gonna see today. Okay, so to get started, I need to go to the terminal. Now just go anywhere in your computer, in your terminal, and we're gonna make a directory for this project. I'm gonna use the command MKDIR, space and then I'm gonna call the director using dash express, you can call it anything you want, this is my name. Press enter and the directory is now created. If I say dir to list, I can see it here. If here is in Linux or Mac, the command to list files is ls. The MKDIR should be the same across systems. Okay, I'm gonna cd space using express to change directory to using express directory. So I'm in the right place. Now, since you installed Node, you should also have NPM, the Node package manager. So I can say NPM space init. And the reason I do this is so it creates a file called package.js.on, JSON, that would be necessary for us to define this as a Node project, and therefore we can install third-party dependencies, that is code that's written by somebody else. In this case, we're gonna install the express library. So we can type, it's gonna ask you a few questions about the content of the package.json file. You can just press enter and accept the default. If you wanna change, you can always change it later. Enter, enter, enter, enter, enter until is this okay? I'm gonna say yes. Okay, now if I do the IR or LS in other systems, I can see there's a file that was created called package.js.on. Now you can open your favorite text editor on this specific directory that we created for the project. For example, I have Visual Studio Code, I could say code, space..meaning current directory, so it will open my thing there. So we got this file that was created by NPM init called package.json, so we define this directory as a Node or NPM project, and we have several properties and values regarding metadata for the project. We don't really care about these right now, so just make sure it's there. Now going back to the terminal, we're gonna install express, and I'm gonna say NPM, space, install, space, express, expres, might take a while. Okay, so what this does is NPM is a Node package manager, so it has a registry of third-party software, and you can pull that code from the registry with the NPM install command. Basically, if you have code that you wrote and you wanna publish that as a package, you can publish that to NPM, and then people can download your code, use the NPM install. So when that happens, what it does, it creates a directory called node underscore modules, and places all the third-party code there. If I show you in Visual Studio, you can see now that the Node modules directory was created, and if I expand that, there's a lot of packages, and the one we installed was express, you can see there's a directory for express. You can see the source code for express is here. Now, the reason there are other folders inside Node modules is because express itself, if you click on the package JSON there, depends on other packages, a lot of other packages. So it also has to download all of that, those other third-party code and put it here, okay? And there you go, if you click package.json, we should now see a property called dependencies, and express is now included there. And what this means is our project depends on the express package, and the version we are dependent upon is this one, 4.18.3. Does anybody have any questions? Yeah, go ahead, you ask the question. Sorry, NPM doesn't get recognized in my command prompt. Did you install Node.js? Is it Node.js I'm installing or the express? So let me share this browser here. One moment. Sorry, the JS I'm installing, I guess I'm using the Windows. This is the website for Node.js. If you don't have Node.js, you should install it. For example, click LTS version. And when you install Node.js, it comes with NPM. Did you install Node.js yet? No, not yet. Okay, that's in progress, yeah. Yeah, make sure to install, just click here, open wizard, MSI, whatever. Okay, thanks. After that is installed, you will get access to Node and NPM. Thomas asks, how do you know if express or any models are installed? I showed you that, right? So going back here to visual studio code, when you install any package for NPM, it will install it under Node modules. So if you verify package.json, you should see under dependencies property, an entry for express. You see express here and the version that was installed. And another way of confirming, if the file is there, go to Node modules, and then verify there's a folder called express here. You see there's express here. So that means it's been installed.
No comments yet (loading...)
No comments yet (loading...)
Did you like the lesson? 😆👍
Consider a donation to support our work: