Skip to content

Instantly share code, notes, and snippets.

@saiccoumar
Last active May 25, 2022 21:22
Show Gist options
  • Save saiccoumar/5dd8aec98403be3dc50ca86bd0114309 to your computer and use it in GitHub Desktop.
Save saiccoumar/5dd8aec98403be3dc50ca86bd0114309 to your computer and use it in GitHub Desktop.
API practice
//imports
var express = require("express"),
app = express(),
mongoose = require("mongoose"),
port = 8000,
url ="mongodb://localhost:27017/api";
//sets the view engine to html, need to change if want to use ejs
mongoose.connect(url, {
useNewUrlParser: true,
useUnifiedTopology: true
})
//should allow static webpages
app.set('view engine', 'ejs');
app.use(express.static(__dirname + "static"));
app.get("/", function (req, res) {
res.render("index.ejs");
});
app.get("/second", function (req, res) {
res.render("second.ejs");
});
//listens to the port
app.listen(port, function () {
console.log("API has started")
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment