Created
March 20, 2019 07:28
-
-
Save topspinppy/bb3969ff755247009fd7ceb6592ac9ea to your computer and use it in GitHub Desktop.
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
| var express = require("express"); | |
| var app = express(); | |
| const mongoose = require("mongoose"); | |
| /////////////////////////////////// เพิ่มส่วนนี้ //////////////////////////////////// | |
| const connect = `mongodb://${process.env.DATABASE_USER}:${ | |
| process.env.DATABASE_PASSWORD | |
| }@${process.env.DATABASE_HOST}:27017/shoppers?authSource=admin`; | |
| mongoose.connect(connect, { useNewUrlParser: true }); | |
| var db = mongoose.connection; | |
| db.on("connected", function() { | |
| console.log("connected"); | |
| }); | |
| const Schema = mongoose.Schema; | |
| const student = new mongoose.Schema({ | |
| id: String, | |
| Name: String, | |
| Surname: String, | |
| thumbnail: String | |
| }); | |
| let students = mongoose.model("student", student); | |
| ////////////////////////////// ถึงส่วนนี้ ////////////////////////////////////////// | |
| app.get("/", async (req, res) => { | |
| const stu = await students.find({}); | |
| console.log(stu); | |
| res.send(stu); | |
| }); | |
| app.get("/user", (req, res) => { | |
| students.create({ | |
| id: "4", | |
| Name: "ssssss", | |
| Surname: "eeeee", | |
| thumbnail: "/index.js/.." | |
| }); | |
| res.send("success"); | |
| }); | |
| app.listen(5000, () => { | |
| console.log("server listening on port 5000"); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment