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 6937173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:19:44+00:00 2026-05-27T12:19:44+00:00

I have a node server and I want to add an external .js file

  • 0

I have a node server and I want to add an external .js file (say something.js). I have this code for now:

var st = require('./js/something');

Where something.js is the JavaScript file inside a /js/ folder. The server compiles and run, but when I try to use functions defined in something.js node tells me they are not defined.

I also tried to run them using like st.s() but nothing happens and I have an error saying that the object has no method s().

Can anyone help me?

Thanks,

EDIT:

logging st gives {} (I obtain it from console.log(JSON.stringify(st)). Also doing console.log(st) gives {} as result.

The content of something.js is just a bunch of functions defined like this

function s() {
    alert("s");
}

function t() {
    alert("t");
}
  • 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-05-27T12:19:45+00:00Added an answer on May 27, 2026 at 12:19 pm

    Node.js uses the CommonJS module format. Essentially values that are attached to the exports object are available to users of the module. So if you are using a module like this

    var st = require('./js/something');
    st.s();
    st.t();
    

    Your module has to export those functions. So you need to attach them to the exports object.

    exports.s = function () {
        console.log("s");
    }
    
    exports.t = function () {
        console.log("t");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a node.js server that i want to be able to handle exceptions
I have a node.js script on my server that I want to run continuously
I have this XML in SQL Server <data> <add key=images value=image/path/img.gif /> <data> I
I have a node with many CCK fields. I want to hide a field
In the sitemap file, I have sitemap Node URL which have more than 1
I have a binary tree where each node can have a value. I want
i have this problem to find a particular xml node l have post this
I want to have a tree in memory, where each node can have multiple
I have this kind of node in my xml document: <parent ...> <a .../>
I have a node in cloud environment which is used now as nginx and

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.