Last active
May 25, 2022 21:22
-
-
Save saiccoumar/5dd8aec98403be3dc50ca86bd0114309 to your computer and use it in GitHub Desktop.
API practice
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
//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