hello.js라는 별도의 파일로 자바 스크립트로 작성된 hello world 프로그램을 실행하려고합니다.
현재 node.js의 Windows 버전을 실행 중입니다.
코드는 콘솔 창에 완벽하게 실행하지만, 내가 어떻게 윈도우 환경에서 경로를 참조 않습니다 .
C:\abc\zyx\hello.js
유닉스에서 $ node hello.js를 보여주는 것 같습니다.
Node.js를 처음 사용합니다. 잘못된 일이 있으면 수정하십시오.
나는 시도했다
> node C:\abc\zyx\hello.js ---- 작동하지 않았다
> C:\abc\zyx\hello.js -작동하지 않았다
업데이트 1 :
hello.js 파일이있는 폴더에 node.exe를 추가했습니다.
c : \ abc \ zyx \ 폴더에 경로 지점을 추가했는데 오류가 발생합니다.
ReferenceError : hello가 정의되지 않았습니다
hello.js의 내용을 참조하십시오
setTimeout(function() {
console.log('World!');
}, 2000);
console.log('Hello');
업데이트 2 :
지금까지 나는이 모든 버전을 시도했지만 그중 아무것도 작동하지 않는 것 같습니다 . 내가 완전히 잘못하고있을 수 있습니다.
>node hello.js
>$ node hello.js
>node.exe hello.js
>node /hello.js
>node \hello.js
> \node \hello.js
> /node /hello.js
> C:\abc\xyz\node.exe C:\abc\xyz\hello.js
> C:\abc\xyz\node.exe C:/abc/xyz/hello.js
> hello.js
> /hello.js
> \hello.js
>node hello
내 파일 구조를 참조하십시오
.
├── hello.js
├── node.exe
└── paths.txt
해결 : node.exe를 실행하는 대신 다음 옵션을 사용하여 명령 프롬프트에서 실행 해보십시오.
c:\>node c:\abc\hello.js
Hello
World! (after 2 secs)
node hello.js대신 시도node hello