Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code doesn't run out of the box anymore #24

Open
thujone opened this issue May 21, 2019 · 4 comments
Open

code doesn't run out of the box anymore #24

thujone opened this issue May 21, 2019 · 4 comments

Comments

@thujone
Copy link

thujone commented May 21, 2019

I don't know if it just needs module updating or what, but mLab doesn't even exist anymore.

I bought the tutorial on udemy yesterday thinking it was new.

@ildx
Copy link

ildx commented May 30, 2019

@thujone

You can use a local instance of Mongodb as well. In that case, the URI would just be something like:

"mongodb://127.0.0.1/lyricaldb"

@thujone
Copy link
Author

thujone commented Jun 13, 2019

thanks for the info.

@dbishoponline
Copy link

code needs to be updated. mongodb url is not valid according to the code. Latest version of mongoose works though

@nenadmarinkovic
Copy link

nenadmarinkovic commented Dec 3, 2019

This works for me! Install latest mongoose (5.7.13) and instead of MLab, use MongoDB Atlas, and change server.js file into something like this:

const express = require("express");
const models = require("./models");
const expressGraphQL = require("express-graphql");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const schema = require("./schema/schema");

const app = express();

const MONGO_URI =
  "mongodb+srv://nenad:<PASSWORDHERE>@cluster0-lxh0n.mongodb.net/lyricaldb";
if (!MONGO_URI) {
  throw new Error("You must provide a MongoDB URI");
}

mongoose.Promise = global.Promise;
mongoose.connect(MONGO_URI, {
  useUnifiedTopology: true,
  useNewUrlParser: true
});
mongoose.connection
  .once("open", () => console.log("Connected to MongoDB."))
  .on("error", error => console.log("Error connecting to MongoLab:", error));

app.use(bodyParser.json());
app.use(
  "/graphql",
  expressGraphQL({
    schema,
    graphiql: true
  })
);

const webpackMiddleware = require("webpack-dev-middleware");
const webpack = require("webpack");
const webpackConfig = require("../webpack.config.js");
app.use(webpackMiddleware(webpack(webpackConfig)));

module.exports = app;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants