weekly updates: learning JS on the backend[2/24/2022]
Will never underestimate “a quick and simple” code-along as it is always informative. Updating y’all my process with this blog markdown using Express.js, Node.js, and MongoDB by Web Dev Simplified. I am stuck on when setting up the articles’ route with the issues of not being able to grab the generic string of article id after creating a new article. There is a long loading process after submitting a new article. I am being taken from articles/new to articles with the content of title, description, and markdown still intact on the form of article, is where I am at by the30 min-ish mark into the hour-ish tutorial.
Queue the effective and fierce Googling on express and body-parser with my data request being sent somewhere on this middleware. I am going through my directory files until I am back on server.js to make sure I have the details down.
const express = require('express')
const bodyParser = require('body-parser')
const mongoose = require('mongoose')
const articleRouter = require('./routes/articles')
const app = express()mongoose.connect('mongodb://localhost/blog',{ useNewUrlParser: true, useUnifiedTopology: true })app.set('view engine', 'ejs')//view engine convert ejs code to html//ejs -here we will be writing all our views using ejsapp.use(express.urlencoded({ extended: false }))app.get('/', (req, res) => {// res.send('Helloo World, from server.js')
//try this one where we are rendering to the view files index.ejs w/ the render() method
//render will pass it to the path we want from the diretory
//index route/main routeconst articles = [{title: 'Test Article',createdAt: new Date(),description: 'Test description'},{title: 'Test Article 2',createdAt: new Date(),description: 'Test description 2'}]// ^ set it to an array w/ one object inside ^res.render('articles/index', {articles: articles})//hooks up the view
//passing articles to the view articles.js ^^})app.use('/articles', articleRouter)app.listen(5000)
Of course, I will paste the error below.
Thank you for tuning into my weekly code-along updates. Happy coding.
Resources
• Web Dev Simplified. “How To Build A Markdown Blog Using Node.js, Express, And MongoDB.” Youtube.com
• Web Dev Simplified. “JavaScript Async Await.” Youtube.com
• Web Dev Simplified. “JavaScript Promises in 10 Minutes.” Youtube.com