Achiel Volckaert
Achiel Volckaert

Reputation: 1014

Cannot find module, pointed to file

I want to include the file "coinModel.js" in the folder "model". It gives the error below. I have the error on linux and on windows 10.

Error: Cannot find module '/model/Coinmodel'
at Function.Module._resolveFilename (module.js:542:15)
at Function.Module._load (module.js:472:25)
at Module.require (module.js:585:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\_node\Api_coinmarktecap\index.js:7:17)
at Module._compile (module.js:641:30)
at Object.Module._extensions..js (module.js:652:10)
at Module.load (module.js:560:32)
at tryModuleLoad (module.js:503:12)
at Function.Module._load (module.js:495:3)

Package.json

    {
  "name": "coinhistory",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/HowestNMCT/proj-VolckaertAchiel.git"
  },
  "author": "Achiel Volckaert",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/HowestNMCT/proj-VolckaertAchiel/issues"
  },
  "homepage": "https://github.com/HowestNMCT/proj-VolckaertAchiel#readme",
  "dependencies": {
    "express": "^4.16.3",
    "model-generator": "^0.7.0",
    "mysql": "^2.15.0",
    "node-schedule": "^1.2.5",
    "request": "^2.83.0",
    "tedious": "^2.1.1"
  }
}

index.js

let coinmodel = require("/model/coinModel");
let Cast = require("model-generator")().Cast;
let mysql = require('mysql');
let express = require('express');
let app = express();   

let con = mysql.createConnection({
    host: "host.be",
    user: "user",
    password: "supersecretpassword",
    database: "mydb"
});
con.connect(function (err) {
    if (err) throw err;
});
let server = app.listen(6000 , function () {
    let host = server.address().address;
    let port = server.address().port;

    console.log("Example app listening at http://%s:%s", host, port)

});

Upvotes: 1

Views: 1410

Answers (1)

ralphtheninja
ralphtheninja

Reputation: 133138

Are you sure /model/Coinmodel is the correct path? If it's the local model directory the path should be ./model/Coinmodel. Also make sure the file is _actually Coinmodel.js and not coinmodel.js.

Upvotes: 1

Related Questions