Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9182147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:29:30+00:00 2026-06-17T18:29:30+00:00

:) I have a somewhat easy answer for you guys to answer as you

  • 0

🙂

I have a somewhat easy answer for you guys to answer as you always do.
Im new at functions and whatnot, iv watched some tutorials about exporting your functions to another node.js application,

Im attempting to generate some random numbers for a external module.

this is what i have setup.

(index.js file)


 function randNumb(topnumber) {
 var randnumber=Math.floor(Math.random()*topnumber)
 }

 module.exports.randNumb();

(run.js)


  var index = require("./run.js");


  console.log(randnumber);

Well My Issue is when i run the index.js file, i get this error from the console.

TypeError: Object #<Object> has no method 'randNumb'
    at Object.<anonymous> (C:\Users\Christopher Allen\Desktop\Node Dev Essential
     s - Random Number\index.js:8:16)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)

I ran the run.js in the beginning, this is what i got.

    ReferenceError: randNumb is not defined
    at Object.<anonymous> (C:\Users\Christopher Allen\Desktop\Node Dev Essential
    s - Random Number\run.js:3:1)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:29:31+00:00Added an answer on June 17, 2026 at 6:29 pm

    In the randNum function, don’t forget to:

    return randnumber;
    

    Also in index.js, export the function like so:

    exports.randNumb = randNumb;
    

    Invoke it like this in run.js:

    console.log(randNumber(10));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is somewhat different question or maybe a easy question. but I have this
I have the somewhat ridiculous need to provide an end-user with a VERY easy
Should be an easy one and might have over complicated the title somewhat. I
UPDATE: I have somewhat resolved the issue. Just in case if anyone runs in
I need to extract a value from a hidden HTML field, have somewhat figured
Setting up a project structure; I am thinking is it better to have somewhat
I have a somewhat strange issue with visual studio. Almost every time I create
I have a somewhat simple Client/Server solution running over C# remoting (System.Runtime.Remoting). The MarshalByRef
I have a somewhat-long-running stored procedure being called from a PB application. I want
I have following somewhat complex sql query which has horrible performance, 'certainly' due to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.