I created a mongoDB form with nodeJS and I can serve the signUp page, but when I click on any other links to go to other pages, it throws "Cannot GET /index.html" for example. I am unsure of how to serve multiple files using nodejs.
var express = require("express");
var app = express();
var port = 3000;
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
var mongoose = require("mongoose");
mongoose.Promise = global.Promise;
mongoose.connect("mongodb://localhost:27017/ClubArchive_Users");
var nameSchema = new mongoose.Schema({
fname: String,
lname: String,
email: String,
uname: String,
pwd :String
});
var User = mongoose.model("User", nameSchema);
app.get("/", (req, res) => {
res.sendFile(__dirname + "/SignUp.html");
});
app.post("/addname", (req, res) => {
var myData = new User(req.body);
myData.save()
.then(item => {
res.sendFile(__dirname + "/index.html");
})
.catch(err => {
res.status(400).send("Unable to save to database");
});
});
app.listen(port, () => {
console.log("Server listening on port " + port);
});