This article is a guide to creating a basic node/Express application with Create, Read, Update and Delete Capabilities. It is designed to not only be a helpful introduction for newcomers but also a handy reference guide with code snippets
<aside> <img src="/icons/drafts_green.svg" alt="/icons/drafts_green.svg" width="40px" /> Andrew Fisher
</aside>
Open a terminal window in your project directory and run the following command to begin installing a new node.js application. It will ask a series of prompts about the project and then set it up for you.
npm init
We’ll use the following basic dependencies for our node.js CRUD functionality, run the following commands to install these packages.
Express → Powerful web framework for node.js
npm install express
Knex.js → SQL query builder for JavaScript
npm install knex
EJS (Embedded JavaScript) → Templating Language for Node Views
npm install ejs
Database Client → Interface with your chosen Relational Database
npm-postgres
npm install pg
npm-mysql
npm install mysql
dotenv → Environment Variables
npm install dotenv
The node.js application we are creating will primarily run out of a central file, which we will call index.js
. The following command will create that file.
touch index.js
As the application serves files to the client, it needs a central store of static files that our HTML can pull from. Let’s call that folder content and add folders for CSS, images and frontend JavaScript using these commands: