2014-09-14 11 views
1

Ive allready stackoverflow에서 여기에 3-4 주제를 읽고,하지만 난 단순히 내 노드를 실행하는 것 같습니다.Node.js 익스프레스 JS - 모듈을 찾을 수 없습니다

나는 실행 해보십시오 :

node app.js local 

을 그리고 반환

Error: Cannot find module './config' 
at Function.Module._resolveFilename (module.js:338:15) 
at Function.Module._load (module.js:280:25) 
at Module.require (module.js:364:17) 
at require (module.js:380:17) 
at Object.<anonymous> (/Users/larsfalcon/Documents/lkrieger/git/testinggrounds/app.js:2:14) 
at Module._compile (module.js:456:26) 
at Object.Module._extensions..js (module.js:474:10) 
at Module.load (module.js:356:32) 
at Function.Module._load (module.js:312:12) 
at Function.Module.runMain (module.js:497:10) 

내가이 명령을 실행하기 전에 내가 할 :

npm i 

그리고 그것은 내가 할 수있는, 내 패키지를 설치 육체적 인 표현 내 node_modules에서 거기에 볼 수 있지만 CLI에서 표현을 실행하려고해도 그것이 아니라 내가 엉덩이 그래서 엉덩이 말한다 그걸 어떻게 든 설치되지 않았습니까?

여기 내 노드를 실행하는 데 필요한 내 2 개의 app.js 및 index.js 파일에 대한 리뷰입니다.

App.js

var config = require('./config')(); 
http.createServer(app).listen(config.port, function(){ 
    console.log('Express server listening on port ' + config.port); 
    }); 

하는 index.js

var config = { 
    local: { 
     mode: 'local', 
     port: 3000 
    }, 
    staging: { 
     mode: 'staging', 
     port: 4000 
    }, 
    production: { 
     mode: 'production', 
     port: 5000 
    } 
} 
module.exports = function(mode) { 
    return config[mode || process.argv[2] || 'local'] || config.local; 
} 

내가 무엇을해야합니까?

+0

'require'문은 어디에 있습니까? –

+0

app.js에서 width가 필요합니다. 죄송합니다. – Nopzen

답변

2

과 같은 폴더에 config.js이 없다는 의미입니다.

업데이트 : 당신은 require('./config/config')을 원할 것입니다.

+0

게시글을 업데이트 해 주실 수 있습니까? app.js에 require를 추가하는 것을 잊어 버렸습니다. – Nopzen

+0

@Nopzen 'config.js'는 어디에 있습니까? –

+0

app.js 파일 옆의/config에서 호출 된 index.js – Nopzen

관련 문제