weekly updates: learning JS on the backend[2/24/2022]

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 route
const 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)
Curious about the reasons behind the unhandledPromiseRejectionWarning… being deprecated at the end.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Toni T Diep

Toni T Diep

multilingual Software Engineer, always learning and growing.