<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Joe Vellella</title>
    <description>The latest articles on DEV Community by Joe Vellella (@covalhalla).</description>
    <link>https://dev.to/covalhalla</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F937156%2F710a5847-7d94-4fdc-9044-104078804f5e.jpeg</url>
      <title>DEV Community: Joe Vellella</title>
      <link>https://dev.to/covalhalla</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/covalhalla"/>
    <language>en</language>
    <item>
      <title>Using TailwindCSS with Express and EJS</title>
      <dc:creator>Joe Vellella</dc:creator>
      <pubDate>Tue, 04 Oct 2022 16:29:03 +0000</pubDate>
      <link>https://dev.to/covalhalla/using-tailwindcss-with-express-and-ejs-2hl0</link>
      <guid>https://dev.to/covalhalla/using-tailwindcss-with-express-and-ejs-2hl0</guid>
      <description>&lt;p&gt;In this article we are going to learn how to quickly set up an Express application using express-generator using EJS as the template engineer and then adding TailwindCSS in order to quickly style/mock up your views!&lt;/p&gt;

&lt;p&gt;First lets make the directory for our app and move into it&lt;br&gt;
&lt;code&gt;mkdir express-ejs-tailwindcss&lt;/code&gt;&lt;br&gt;
&lt;code&gt;cd express-ejs-tailwindcss/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Lets install and run express-generator&lt;br&gt;
&lt;code&gt;npx express-generator&lt;/code&gt;&lt;br&gt;
&lt;code&gt;express --view=ejs&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Follow the directions of express-generator and run &lt;code&gt;npm install&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To make development easier, lets install nodemon so the server refreshes on each save.&lt;br&gt;
&lt;code&gt;npm install nodemon --save-dev&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Open up your project and add the following script to your package.json file.&lt;br&gt;
&lt;code&gt;"devstart": "nodemon ./bin/www",&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Run the npm devstart to see the default index.ejs view from express-generator.&lt;/p&gt;

&lt;p&gt;Now that express and EJS are installed, lets move onto TailwindCSS! Run the following:&lt;br&gt;
&lt;code&gt;npm install tailwindcss postcss autoprefixer postcss-cli&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Lets generator our tailwind.config.js and postcss.config.js files with: &lt;br&gt;
&lt;code&gt;npx tailwindcss init -p&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Copy the following code to your tailwind.config.js file&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/** @type {import('tailwindcss').Config} */&lt;br&gt;
module.exports = {&lt;br&gt;
  content: ['./views/*.ejs'],&lt;br&gt;
  theme: {&lt;br&gt;
    extend: {},&lt;br&gt;
  },&lt;br&gt;
  plugins: [&lt;br&gt;
    {&lt;br&gt;
      tailwindcss: {},&lt;br&gt;
      autoprefixer: {},&lt;br&gt;
    },&lt;br&gt;
  ],&lt;br&gt;
};&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Create a tailwind.css file in the public/stylesheets folder and add the following to the file:&lt;br&gt;
&lt;code&gt;@tailwind base;&lt;br&gt;
@tailwind components;&lt;br&gt;
@tailwind utilities;&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Add the following script to the package.json file.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"tailwind:css": "postcss public/stylesheets/tailwind.css -o public/stylesheets/style.css"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Add a tailwind class to your project! In the index.ejs file modify the following line as a test:&lt;br&gt;
&lt;code&gt;&amp;lt;p class="text-red-500"&amp;gt;Welcome to &amp;lt;%= title %&amp;gt;&amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Run the tailwind:css script, then devstart, open your browser to see your tailwind styled page with Express and EJS!&lt;/p&gt;

</description>
      <category>express</category>
      <category>tailwindcss</category>
      <category>ejs</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
