- Create a
/netlify
folder and inside create/functions
folder, and inside create a.js
file for your function - OPTIONAL: require MongoClient if you are using MongoDB
- Create an async function named
handler
- OPTIONAL: Connect to the database, get your data, then close DB connection
- Return an object with
statusCode
,headers
(optional), andbody
properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// npm i express mongoose ejs | |
// in app.js | |
const express = require('express'); | |
const app = express(); | |
app.get('/', (req, res) => { | |
res.send('Home Route'); | |
}); | |
app.listen(3000, () => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add to app.js | |
const path = require('path'); | |
/* Set EJS as the view engine */ | |
app.set('view engine', 'ejs'); | |
app.set('views', path.join(__dirname, 'views')); | |
// change res.send to res.render | |
app.get('/', (req, res) => { | |
res.render('home'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// npm i express mongoose | |
// create a /models folder, inside create retreat.js, | |
// model name = 'Retreat', the schema = RetreatSchema | |
const mongoose = require('mongoose'); | |
const { Schema } = mongoose; | |
const RetreatSchema = new mongoose.Schema({ | |
title: String, | |
image: String, | |
price: Number, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (process.env.NODE_ENV !== 'production') { | |
require('dotenv').config(); | |
} | |
const express = require('express'); | |
const path = require('path'); | |
const mongoose = require('mongoose'); | |
const ejsMate = require('ejs-mate'); | |
const methodOverride = require('method-override'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Simpler version on my portfolio site: | |
https://jameskernicky.netlify.app/ | |
https://github.com/Kernix13/personal-portfolio | |
--> | |
<button id="back-to-top-btn"><i class="fa-solid fa-angle-up"></i></button> | |
<!-- Bootstrap icon instead of font awesome --> | |
<svg | |
xmlns="http://www.w3.org/2000/svg" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
details { | |
border: 1px solid #ccc; | |
border-radius: 5px; | |
margin-bottom: 10px; | |
padding: 10px; | |
transition: border 300ms ease-in-out, padding 300ms ease-in-out; | |
} | |
details:focus { | |
outline: 1px solid #CDCDE4; |
OlderNewer