1
私はNodeJSを初めて使い、NodeJSのガイドに沿ってNodeJSでサーバーを作成しようとしています。私はすでにNodeJSを自分のコンピュータにインストールし、次のコードでapp.jsファイルを作成します。NodeJSを使い始める - nodeJSでモジュールを見つけることができない
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(port, hostname,() => {
console.log(`Server running at http://${hostname}:${port}/`);
});
はその後、私はCMD(Windowsの10)でnode app.js
のコマンドを入力してコードを実行しようとしました。その後、次のエラーが表示されます。
C:\Users\Nuwanst\Documents\NodeJS\test2>node appjs
module.js:471
throw err;
^
Error: Cannot find module 'C:\Users\Nuwanst\Documents\NodeJS\test2\appjs'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:504:3
これを修正するにはどうすればよいですか?