diff --git a/src/index.ts b/src/index.ts index 6d84fb6058ad094cc870b2ac81981961f5bcc7a0..ff0948f1a6b7c6b37332a058bae7de3b776bc4ab 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,18 @@ import "./utils/env" import express, { Request, Response, NextFunction, Application } from "express"; +import mongoose from "mongoose"; import bodyParser from "body-parser"; import expressSession from "express-session"; import authRoute from './routes/auth'; import newsRoute from './routes/news'; +mongoose.connect('mongodb://localhost:27017/bodysch', { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true } ).then( + () => { console.log("Connected to database") }, +).catch(err => { + console.log("MongoDB connection error. Please make sure MongoDB is running. " + err); + // process.exit(); +}); + const app: Application = express(); app.use(bodyParser.json()); // for parsing application/json diff --git a/src/models/NewsSchema.ts b/src/models/NewsSchema.ts index 192d2f32d45fead8f1c85c329f550fb9257a6994..d49e39dfc1b0d321f4130dadfd3de6f6ef99ec71 100644 --- a/src/models/NewsSchema.ts +++ b/src/models/NewsSchema.ts @@ -11,7 +11,7 @@ interface INews extends Document { // id: IUser["_id"], userName: string, }, */ - publishedAt: Date + publishedAt: string } const NewsSchema = new Schema({ @@ -25,7 +25,7 @@ const NewsSchema = new Schema({ id: { type: Schema.Types.ObjectId, required: true }, userName: { type: String, required: true } }, */ - publishedAt: { type: Date, required: true }, + publishedAt: { type: String, required: true }, }); export default model<INews>('News', NewsSchema); \ No newline at end of file