-1

I am trying to run my Express project but it won't execute.Following is my package.json file

enter image description here

I am writing following command in terminal but noting happens. FYI, I am in the right directory

enter image description here

Here is my index.js file

require("./models/User");
require("./models/Track");
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const authRoutes = require("./routes/authRoutes");
const trackRoutes = require("./routes/trackRoutes");

const requireAuth = require("./middlewares/requireAuth");

const app = express();

app.use(bodyParser.json());
app.use(authRoutes);
app.use(trackRoutes);

const mongoUri =
  "MY_MONGO_URL";
mongoose.connect(mongoUri, {
  useNewUrlParser: true,
  useCreateIndex: true
});

mongoose.connections.concat("connected", () => {
  console.log("Connected to mongo instance");
});

mongoose.connection.on("error", err => {
  console.error("Error connecting to mongo", err);
});

app.get("/", requireAuth, (req, res) => {
  res.send(`Your Email: ${req.user.email}`);
});

app.listen(3000, () => {
  console.log("Listening on Port 3000");
});
Go Fudge YourSelves
  • 139
  • 1
  • 2
  • 10
Chup bae
  • 69
  • 1
  • 7

2 Answers2

0

I would suggest changing your script as below:

"scripts": {
    "dev": "nodemon index.js"
 },

Then from the root of your project, you can start your server:

npm run dev
thefabdev
  • 753
  • 1
  • 7
  • 20
0

I had to use yarn run dev as I am using yarn

Chup bae
  • 69
  • 1
  • 7