-
Notifications
You must be signed in to change notification settings - Fork 511
Expand file tree
/
Copy pathserver.js
More file actions
27 lines (22 loc) · 785 Bytes
/
server.js
File metadata and controls
27 lines (22 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import cors from "cors";
import express from "express";
import mongoose from "mongoose";
const mongoUrl = process.env.MONGO_URL || "mongodb://localhost/project-mongo";
mongoose.connect(mongoUrl);
mongoose.Promise = Promise;
// Defines the port the app will run on. Defaults to 8080, but can be overridden
// when starting the server. Example command to overwrite PORT env variable value:
// PORT=9000 npm start
const port = process.env.PORT || 8080;
const app = express();
// Add middlewares to enable cors and json body parsing
app.use(cors());
app.use(express.json());
// Start defining your routes here
app.get("/", (req, res) => {
res.send("Hello Technigo!");
});
// Start the server
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});