- Basic Setup (Mongoose + Express):
- mkdir test
- cd test
- npm init -y
-
npm i express ejs mongoose
-
touch index.js
- mkdir views
- nodemon index.js
index.js
const express = require('express'); const app = express(); const path = require('path'); const mongoose = require('mongoose'); mongoose.connect('mongodb://localhost:27017/farmStand', { useNewUrlParser: true, useUnifiedTopology: true }) .then(() => { console.log("MONGO CONNECTION OPEN!!!") }) .catch(err => { console.log("OH NO MONGO CONNECTION ERROR!!!!") console.log(err) }) app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'ejs'); app.get('/dog', (req, res) => { res.send('Woof!') }) app.listen('3000', () => { console.log("APP IS LISTENING ON PORT 3000!") })