Creating a custom module in node for GraphQL?

Viewed 940

I'm currently following this tutorial in an attempt to learn GraphQL with React but I'm getting the following error when trying to run npm start:

Error: Cannot find module 'notarealdb'
Require stack:
- /Users/user/Workspace/intro-to-graphql/db.js
- /Users/user/Workspace/intro-to-graphql/server.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
    at Function.Module._load (internal/modules/cjs/loader.js:864:27)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (/Users/user/Workspace/intro-to-graphql/db.js:1:23)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Module.require (internal/modules/cjs/loader.js:1044:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/user/Workspace/intro-to-graphql/db.js',
    '/Users/user/Workspace/intro-to-graphql/server.js'
  ]
}
[nodemon] app crashed - waiting for file changes before starting...

I'm completely new to GraphQL, so I think what's going on here

const { DataStore } = require('notarealdb');

const store = new DataStore('./data');

is that we're creating a new DataStore that we interact with in place of interacting with a traditional database, and we're replacing notarealdb with a name that maps to what is found in ./data. I guess notarealdb has to map to something, but the tutorial doesn't mention what it is.

Does anyone know exactly what this tutorial means?

2 Answers

You can install notarealdb by using this code

npm install notarealdb@0.2.2

And if error comes then use

sudo npm install notarealdb@0.2.2

Related