Search code examples
javascriptnode.jsnpm-installairtable

Can't find module airtable even though I ran npm install airtable


I am currently trying to use the airtable api for the backend of my website, but when I write (nodejs)

var Airtable = require('airtable');

and execute the file via node [filepath] the command prompt throws an error saying

Error: Cannot find module 'airtable'

I have already written

npm install airtable

so the module should be installed, right?

I would expect, with the full code, for it to set up a server on localhost port 3000, but I can't get past the require() statement.

package.json (some info omitted):

{
  "name": "package.json",
  "version": "1.0.0",
  "main": "index.js",
  "dependencies": {
    "airtable": "^0.7.2",
    "express": "^4.17.1",
    "require": "^2.4.20"
  }
}

Solution

  • Providing an official answer for anyone else with this problem:

    To install a Node module to be used in your project, you must first initialize a package.json file. This will tell npm to create a node_modules/ folder and install the module in your project directory.

    You can initialize that file with the command:

    $ npm init -y
    

    (The -y flag tells the command to create the file using default values, otherwise it will promt you for all of the values)

    More documentation on npm init