Creating a Node + Express + MongoDB Web Application from Scratch
Welcome to this tutorial on how to build a CRUD web application using Node, Express and MongoDB. In order to follow along, you’ll need a code editor, passion and latest version of NodeJS installed on your local machine.
- If you’re on windows, open your Command Line (CMD) or Powershell. If you’re a Mac user, open your Terminal. Navigate to the directory where you want your project folder to be and do “mkdir myproject”. This will create a new directory. Navigate to your project directory and do “npm init -y”, which will create a package.json file with default configurations.
- Now open your favorite code editor (mine is Sublime Text <3). On the root level, create a server.js file. We start by importing the dependencies.
- In your root directory, create 2 new folders, “public”, to hold our assets, and “views” to put the EJS templates in.
- Navigate inside your “views” folder and make a new folder called “partials” that will hold partial views such as Footer, Navbar, Sidebar etc.
- Inside the “views” folder, make a new file and call it “index.ejs”. This file is going to be rendered whenever a GET request is made to http://localhost:8080/
You can learn more about EJS by reading their official documentation. Few alternatives to EJS are Handlebars, Jade, Mustache and Pug.
- Now we can pass data from our server.js to file to our views.
To be continued.. 🙂