Creating an express web app
Express has long been the most popular choice web framework, which is unsurprising since it was the first Node web framework of a high enough quality for mass consumption while also drawing from familiar paradigms presented in the Sinatra web framework for Ruby on Rails.
In this recipe, we'll look at how to put together an Express web application.
Getting ready
Let's create a folder called app
, initialize it as a package, and install express
:
$ mkdir app $ cd app$ npm install --save express
How to do it...
Let's start by creating a few files:
$ touch index.js $ mkdir routes public $ touch routes/index.js$ touch public/styles.css
Now let's open the index.js
file in our favorite editor, and prepare to write some code.
At the top of the file we'll load the following dependencies:
const {join} = require('path') const express = require('express') const index = require('./routes/index')
We'll write the routes/index.js
file shortly, but for now let's continue writing the index...