Coder Social home page Coder Social logo

andrewjbateman / meen-stack-articles Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 345 KB

:memo: This app displays articles in a grid of Bootstrap cards. It uses the MongoDB, Express, Embedded Javascript Templating (EJS) & Node.js (MEEN) stack to perform Create, Read, Update and Delete (CRUD) operations. EJS is a templating language that uses javascript to produce the HTML template markup. I wanted to see if using EJS resulted in quicker rendering. Backend: Express routes and controllers were created in separate folders to make the code more readable. A Mongoose schema was used for the Note model.Frontend: I used the vue-moment Moment.js filter dependency to extract a more readable time format from the database UTC timestamp using a pipe.

License: MIT License

JavaScript 27.41% Shell 0.23% EJS 72.36%
meen-stack-articles article-page meen ejs articles-array mongodb-atlas nodejs full-stack javascript html5

meen-stack-articles's Introduction

โšก MEEN Stack Articles

  • Displays articles, written using markup language, on Bootstrap cards.
  • It uses the MongoDB, Express, Ejs & Node.js (MEEN) stack to perform Create, Read, Update and Delete (CRUD) operations.
  • Note: to open web links in a new window use: ctrl+click on link

GitHub repo size GitHub pull requests GitHub Repo stars GitHub last commit

๐Ÿ“„ Table of contents

๐Ÿ“š General info

  • The EJS (Express JS) template engine enables the use of static template files with dynamic content. It is faster and simpler than Angular or React but has less features.
  • Partials were used to be able to reuse the same code, eg header.ejs - which includes the Bootstrap CDN link & navbar.ejs - a common top navigation bar.
  • Index (home) page: Article images with summaries are displayed in a responsive grid so they wrap around nicely as the screen size changes. The number of articles is displayed at the top using the articles array length.
  • Display_all Page: The header shows the creation date, formatted using the Javascript 'toLocaleDateString' method. The footer has buttons to redirect back to the home page and to the article edit page. There is also an article delete button with a user confirmation alert.
  • Article Edit Page: User can change all article fields. Date will update automatically to todays date. Footer has edit cancel and save buttons. 2nd nav menu and credit for image
  • New Article page: User can create a new article by filling in validated form fields.
  • About page: Displays information about the app. Footer has links to the 4 MEEN full-stack technologies used.
  • Contact page: Displays Github API data on app author with links to personal website and contact page.

๐Ÿ“ท Screenshots

Example screenshot Example screenshot Example screenshot

๐Ÿ“ถ Technologies

  • EJS v3 Embedded Javascript templating to generate HTML markup
  • Express method-override v3 to be able to use HTTP verbs PUT or DELETE
  • Express v4 framework for Node.js
  • MongoDB Atlas free shared DB cluster used
  • Mongoose v6 object modelling for Node.js
  • marked v4 to convert markdown to html
  • Slugify v1 to replace unwanted characters etc
  • Dompurify v3 used as an XSS sanitizer for the output HTML from the markdown text
  • Node-fetch v2 light-weight npm module that adds a window.fetch compatible API to Node.js, used here to fetch my data from the Github API
  • Material Icons svg data used to create a public/images folder of icons I can reuse
  • Unsplash images - random images used for building article card array. https://source.unsplash.com/random/400x300 supplies a random image to the specified size 400x300
  • Day.js v1 used with relative time plugin to calculate how long ago article was written.

๐Ÿ’พ Setup

  • Run npm i to install dependencies.
  • Create a root-level .env file and add MongoDB connection string: MONGO_URI="MongoDB connection string"
  • Run npm run dev to create an Ejs client and backend server concurrently.
  • Navigate to http://localhost:4000/ to see frontend (refresh after changes - does not auto-update).

๐Ÿ’ป Code Examples

  • extract from controllers.js to get length of articles array and convert this to a variable totalArticles to be used in index.ejs to show total number of articles. Variable articlesString also created in controllers.js and used in the HTML markup to show the word article or articles.
// Display articles list in date order
exports.article_list = async (req, res) => {
	try {
		const articles = await Article.find().sort({ createdAt: 'desc' });
		const totalArticles = articles.length;
		const articlesString = articles.length === 1 ? ' article' : ' articles';
		res.render('articles/index', {
			articles,
			totalArticles,
			articlesString,
		});
	} catch (err) {
		res.status(500).json({ message: err.message });
	}
};
		<div class="d-flex justify-content-center pt-3 pl-2">
			<div class="alert alert-success border-dark p-2 mb-1" role="alert">
				<p class="mb-0 text-center">
					You have
					<span class="badge badge-pill badge-light" style="font-size: 18px"
						><%= totalArticles%></span
					><%= articlesString %>
				</p>
			</div>
		</div>

๐Ÿ†’ Features

  • The backend code separates Express controller functions from routes: routes forward requests to the applicable controllers and controllers read/write data using models.
  • Updating an article will automatically update the date so it goes to the front of the (date-sorted) notes list

๐Ÿ“‹ Status & To-Do List

  • Status: Working. Refactor - add functionality.
  • To-Do: Add articles for screen prints. Add modals/toasts to say if title is repeated etc. Add markdown editor?

๐Ÿ‘ Inspiration

๐Ÿ“ License

  • This project is licensed under the terms of the MIT license.

โœ‰๏ธ Contact

meen-stack-articles's People

Contributors

andrewjbateman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.