SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Help -- Cannot find module './models/User.js'

    Got this book recently and started working on the example and I hit a road block. Searched through the forums. Went through the internet. Not much success. I am not sure if the issue is because of node.js or because of permission on the OS.

    Here is the problem statement
    OS: Ubuntu Linux, installed on Virtual Box. Virtual Box is running on Win8.

    Steps:
    Login to Linux on Virtual box, through Cygwing client
    Execute sudo npm install -g express@2.5.8 (pg. 7)
    Execute express authentication (pg. 8)
    Change directory cd authentication
    Execute node app.js

    Open the browser and type http://myVirtualBoxIPAddress:3000
    and observe “Welcome to Express.” message displayed in the browser. So far so good. Everything seems to work just fine.

    Now I come to page 12. Per the instruction, I create a directory under authentication folder and name the directory as "lib" using below command
    [username@myUbuntu:~/sitepoint/authentication]$ mkdir lib

    then create the db.js file using emacs. Save the file. Yes, I have setup the mongoDB on mongolab, tested the connection and everything works.

    Then I create the Users.js file by below steps
    [username@myUbuntu:~/sitepoint/authentication]$ mkdir models
    [username@myUbuntu:~/sitepoint/authentication]$ cd models
    [username@myUbuntu:~/sitepoint/authentication/models]$ emacs -nw Users.js



    type in the code given on page 14 and save the file. My app.js looks like below
    Code JavaScript:
     
    var express = require('express') , routes = require('./routes') , fs = require('fs') , User = require('./models/User.js');


    Now I try to run app.js from authentication folder and I get the below error


    module.js:340
    throw err;
    ^
    Error: Cannot find module './models/User.js'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/username/authentication/app.js:10:12)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)


    I have been struggling with this error for 2 days and have given up. If anyone knows what the solution may be, please help. This will be highly appreciated.

    Thanks in advance,

    Vinay

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,077
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    What's the name, publisher and edition of the book that you're working from?

    Check that file Users.js exists that that it's where you actually expect it to be located (using whatever the Linux equivlant of Windows Explorer is called).
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks...

    The book name - "Jump Start Node JS" by Don Nguyen, Published by Sitepoint, Copyright 2012.

    Yes, the Users.js file exists. I just created the directory and the file.

  4. #4
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,077
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Check your spellings of where the file is stored and that the script is looking for. The script is looking for "User.js" but the file is called "Users.js". If you named the file exactly as in the book (I don't have a copy of the book on me to look at) then there's probably an error in the book.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  5. #5
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!! You nailed it !

    I was not paying attention to the spelling and that was the biggest mistake. I had the filename as "Users.js" on the disk and was referring it as "User.js" in the code.

    I was about to give-up on this learning . Thanks for holding the hand here. Appreciate it.

    Thanks again.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •