ga-wdi-exercises / pbj-project3

[project]
0 stars 2 forks source link

Why does express think this is a module? #41

Closed Curtismn87 closed 9 years ago

Curtismn87 commented 9 years ago
var stocksController = require("./app/controllers/stocks");
app.use("/test#", stocksController);

Once we add these two lines of code nodemon crashes and tell us in this line of code which is in our stocks controller

var Stock = require("../db/connection").models.Stock;

that "../db/connection" is not a module. Why does it think this path is now a module?

RobertAKARobin commented 9 years ago

Can you show the exact text of the error? My guess is that the path isn't correct. Maybe it should be ./db/connection instead of ../db/connection.

Curtismn87 commented 9 years ago
var express = require("express");
var router = express.Router();
var Stock = require("../db/connection").models.Stock;

Error: Cannot find module '../db/connection'
Error: Cannot find module './db/connection'
Error: Cannot find module '/db/connection'
Error: Cannot find module 'EVERYTHINGisBROKEN/db/connection'

Here is the exact error:

Error: Cannot find module '../db/connection'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/curtismn87/WDI/projects/myStox2/app/controllers/stocks.js:4:13)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
26 Aug 15:35:29 - [nodemon] app crashed - waiting for file changes before starting...
RobertAKARobin commented 9 years ago

Can you push your code to GH and give me the link? I'll take a look.

Curtismn87 commented 9 years ago

https://github.com/tomBeach/MyStox2

RobertAKARobin commented 9 years ago

You need ../../db/connection.

mattscilipoti commented 9 years ago

It couldn't find the file, so it started looking for a module of that name.

Curtismn87 commented 9 years ago

Ahhhh works great! Thanks!