Intel® Makers
Intel® Edison, Intel® Joule™, Intel® Curie™, Intel® Galileo
Announcements
Welcome - This is a Peer-to-Peer Forum only. Intel has discontinued these products but you may find support from other customers on this Forum
9880 Discussions

How to require my own app.js file in XDK

eyuan2
New Contributor I
1,048 Views

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
158 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
159 Views

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

And seems working now

Reply