javascript - Node.js requre not working as expected -


i have used node , node express generator generate node express code. worked fine, until had deploy ti server.

by default there couple of files :

.bin/www ( there have var app = require('../app'); )

app.js 

my hosting requires have name of server.js starting point. moved www , and renamed server.js

and there structure:

server.js  app.js 

now problem in line have require var app = require('../app');

i have tried change to

var app = require('app'); var app = require('app.js'); var app = require('./app'); var app = require('app/app'); --> move of app different folder 

but without success. doing wrong?

try this:

var app = require('./app');

not prepending ./ in front of filename indicates want require module instead of file.

edit:

try following:

var path = require('path'); var app = require(path.resolve(__dirname, './app.js')); 

more info on __dirname global can found here.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -