0

get(function (){ console.log(' Hello world'); });

I have this js file that contains some message in a project folder in my node eclipse. I want access that js file to my current project folder using path. How to access that file to my current folder. Please give me the code for both js files for accessing and exporting. Please help me. Thank you

3
  • use require('file-name.js'); Commented Jul 9, 2016 at 12:11
  • I dont realy understand for what you are asking. But if you want to only use the js file you can do it with require, like normal. e.g. const modul = require('../other/project/modul.js') Commented Jul 9, 2016 at 12:12
  • @Julian I want to get a js file from another project folder to my current project folder like the above code. But that was not working. Commented Jul 9, 2016 at 12:30

1 Answer 1

2

Try this:
// common.js

module.exports = {
    theFunc: function(obj){
         console.log(' Hello world');
    };
}

// another.js

var common = require('common.js');  // with full path
common.theFunc();
Sign up to request clarification or add additional context in comments.

10 Comments

This was a nice code. But when I try to run my another.js, it shows the error Cannot find module '../Work/routes/get.js'. and this is my path I set to the another.js. another.js I just say, file is different.
is this file get.js outside your current project? you can try this code into any demo project for understand.
Yes. get.js is outside of my current project. I want to get this get.js file to my current project. and show the content. Thank you
then how is it possible. will you upload both these project at time of deployment? You need to put this into same project
yes it is possible with hack, when ever your node server started you need to pull that file from that server via http.request & create a file on your current server or store in node caches.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.