2017-10-30 1 views
1

저는 node.js를 처음 사용 했으므로 모듈 websocket을 사용해야합니다. 내 서버 :Node.js - 'websocket'모듈을 찾을 수 없습니다

$ cat /etc/centos-release 
CentOS Linux release 7.2.1511 (Core) 

$ node --version 
v6.11.5 

$ npm --version 
3.10.10 

$ npm install websocket와 모듈을 설치,하지만 난 내 파일을 시도 할 때 그것은 나에게주는이 :

$ node /var/www/js/test.js 
module.js:471 
    throw err; 
    ^

Error: Cannot find module 'websocket' 

이 내 JS 파일의 첫 번째 라인 :

var WebSocketClient = require('websocket').client; 

다음 명령을 시도했습니다.

$ npm install websocket (with and without -g flag) 
$ npm link websocket 
$ npm install -d 

하지만 아무런 도움이되지 않았습니다.

package.json

:

{ 
    "name": "root", 
    "version": "1.0.0", 
    "description": "", 
    "main": "index.js", 
    "dependencies": { 
    "websocket": "^1.0.25" 
    }, 
    "devDependencies": {}, 
    "scripts": { 
    "test": "echo \"Error: no test specified\" && exit 1" 
    }, 
    "author": "", 
    "license": "ISC" 
} 
+0

패키지에서 아무것도, JSON 파일 –

+0

갱신 노드 버전 –

+0

@rahulmr이있다 업데이트 된 질문, 노드를 업데이트하려고 시도합니다 – debute

답변

0

는 노드 디렉토리의 루트에있어 가정, test.js에 추가

process.chdir(__dirname);

또는 :

cd /var/www/js/ && node test.js합니다.

작업 디렉토리는 node_modulespackage.json 인 디렉토리 여야합니다.

노드 응용 프로그램에 대한 작업 디렉토리를 인쇄하려면 :

console.log(process.cwd());

+0

고마워,하지만 이미 노드를 v8.8.1에 업데이트하는 것으로 관리 했어. – debute

0

당신이 파일이 var websocket = require('websocket');을 시도해야

+0

최신 버전으로 노드를 업데이트하는 걸 도왔다. – debute

관련 문제