error on executing the program我是node.js的初学者。我已经按照以下博客中的所有步骤进行了操作:
http://blog.teamtreehouse.com/install-node-js-npm-windows
我也得到了节点版本和npm版本。 但是当我尝试从cmd运行js文件时没有得到输出。
console.log('Node is installed!');
上面一行中提到了js文件的内容。
请帮帮我!!
提前致谢
答案 0 :(得分:0)
似乎 c drive 或错误的目录
中没有 hello.j转到任何文件夹并制作你的hello.js然后导航到cmd中的那个文件夹然后写
node hello.js // .js is optional
在上图中你可以收到错误helloo cant find module becoz i dont have any file with name helloo.js
假设您的文件位于D驱动器中,然后转到 D 驱动器和wirte
您可以制作简单的 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);
});