DEV Community

kishan kumar
kishan kumar

Posted on

Creating a simple website with Node.js, Express, and EJS

This blog is for beginners who wanted to start with Node.js. We will be creating a simple website design with Node.js and the Express framework and will be using the EJS view engine to manage our HTML code.

Prerequisites

Step 1: Install nodejs and npm

If everything installed correctly, open terminal and type node -v and npm -v and you should get the following output based on the version you have installed


node -v
8.9.1
npm -v
5.8.0

Step 2: Install Express generator package globally (g stand for global in command)

npm install express-generator -g

Step 3: To run our node server we will install the Nodemon package globally

npm install nodemon -g

Open a terminal and move to your directory where you want your code to reside and type

express --view=ejs mywebsite

As I told we will be using ejs view engine to manage our HTML code throughout our tutorial and this command will create the skeleton of our node application and will set ejs as our default view engine

The next step is to install all dependencies listed in mywebsite/package.json file. Move to your myapp directory and type

npm install

Now we are all set to run our node server, type command

nodemon start

If you see the following output in your terminal, voila!!! the node server is up and running

[nodemon] 1.11.0
[nodemon] to restart at any time, enter rs
[nodemon] watching: .
[nodemon] starting node ./bin/www start

Read More about this article Creating a simple website with Node.js, Express, and EJS

Top comments (0)