Created
January 29, 2021 15:11
-
-
Save lmas3009/770051fc7ad006411833d57e0e50d0c9 to your computer and use it in GitHub Desktop.
Rest API using MEN (MongoDB,ExpressJs and NodeJs)
This file contains 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
import express from 'express' | |
import mongoose from "mongoose" | |
import Cors from 'cors' | |
var app = express() | |
var port = process.env.PORT || 8080 | |
app.use(express.json()) | |
app.use(Cors()) | |
var Connection_url = 'mongodb+srv://Rest-API_lmas:<password>@cluster0.gklyj.mongodb.net/<dbname>?retryWrites=true&w=majority' | |
mongoose.connect(Connection_url, { | |
useNewUrlParser: true, | |
useCreateIndex: true, | |
useUnifiedTopology: true | |
}) | |
app.get("/", function (req, res){ | |
res.send( "Welcome to Tutorial of REST API using MongoDB, ExpressJS and NodeJS"); | |
}) | |
app.listen(port) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment