Community
cancel
Showing results for 
Search instead for 
Did you mean: 
eyuan2
New Contributor I
964 Views

How to require my own app.js file in XDK

Jump to solution

Hey guys,

Do you know how to add my own app.js file into main.js. so that i can invoke some function from app.js to main.js

Just like a include file in C. We have a app.h and app.c ,then we can include"app.h" in main.c. so that we can invoke the function in main.c

I followed an instruction and find out there is a error while compile it.

/************************************/

in app.js

var app= function()

{

//do something here

};

module.exports = app;

/*****************************************/

in main.js

var app= require('app.js')

function loop()

{

//do something here.

}

 

 

There is a error says cannot find out the module of app.js.

I was wondering whether i need to modify something in package.json?

1 Solution
eyuan2
New Contributor I
74 Views

Just figured out i need to use var app= require('./app.js') instead of var app= require('app.js')

And seems working now

View solution in original post

1 Reply
eyuan2
New Contributor I
75 Views

Just figured out i need to use var app= require('./app.js') instead of var app= require('app.js')

And seems working now

View solution in original post

Reply