Skip to content

Instantly share code, notes, and snippets.

View Kernix13's full-sized avatar
💭
Still looking for a job - but losing hope

Jim Kernicky Kernix13

💭
Still looking for a job - but losing hope
View GitHub Profile
@Kernix13
Kernix13 / app.js
Created March 31, 2024 14:53
Basic Node and Express.js Server
// 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, () => {
@Kernix13
Kernix13 / app.js
Created March 31, 2024 14:54
EJS views and first basic route (Node and Express.js)
// 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');
@Kernix13
Kernix13 / retreat.js
Created March 31, 2024 15:01
Mongoose model and schema
// 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,
@Kernix13
Kernix13 / app.js
Created March 31, 2024 15:07
Full-stack EJS, Node & Express app.js example
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');
@Kernix13
Kernix13 / NetlifyFunctions.md
Created March 31, 2024 15:35
Netlify function example

Structure of a Netlify Function

  1. Create a /netlify folder and inside create /functions folder, and inside create a .js file for your function
  2. OPTIONAL: require MongoClient if you are using MongoDB
  3. Create an async function named handler
  4. OPTIONAL: Connect to the database, get your data, then close DB connection
  5. Return an object with statusCode, headers (optional), and body properties
@Kernix13
Kernix13 / index.html
Last active April 6, 2024 16:18
Back To Top Button
<!-- 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"