2016-12-13 8 views
0
コマンドでプログラムをNode.jsの実行することができません

error on executing the program私は.IをNode.jsのための初心者ですが、以下のブログからすべての手順に従っていますプロンプト

http://blog.teamtreehouse.com/install-node-js-npm-windows

私はノードのバージョンとNPMを得ましたバージョンも。 しかし、cmdからjsファイルを実行しようとすると出力が得られません。

console.log('Node is installed!'); 

上記の行にjsファイルの内容が記載されています。

私を助けてください!

+2

「hello.js」fi 'node hello.js'コマンドを実行しようとしているディレクトリと同じディレクトリにありますか? –

+0

これで問題は解決しましたか? – Adiii

+0

ノードが正しく設定されていることを確認するには、「node」と入力してください。これにより、ノードのコマンドラインが表示され、jsを直接実行できます。コマンドプロンプトで現在表示されているディレクトリと同じディレクトリにあるtest.jsというjsファイルを実行するには、 "node test"と入力します。 –

答えて

0

そのはに移動し、その後そこにはhello.j Cドライブまたは間違ったディレクトリ内

後藤任意のフォルダがありませんし、あなたのhello.jsを作るようで、事前に

感謝CMDでそのフォルダは、書き込み

node hello.js // .js is optional 

enter image description here

もし上記の写真の

私はエラーがカントは、あなたのファイルをDドライブに、その後のgoto Dドライブとwirteあなたが作ることができ

enter image description here

であると仮定し、私dont have any file with name helloo.js

becozモジュールを見つけるhelloo受け取ることができますシンプルhello.jsサーバ

//Lets re quire/import the HTTP module 
var http = require('http'); 
//Lets define a port we want to listen to 
const PORT=8080; 
//We need a function which handles requests and send response 
//Create a server 
var server = http.createServer(function (request, response){ 
    response.end('It Works!! Path Hit: ' + request.url); 
}); 
//Lets start our server 
server.listen(PORT, function(){ 
    //Callback triggered when server is successfully listening. Hurray! 
    console.log("Server listening on: http://localhost:%s", PORT); 
});