Node.js学习2~在控制台命令行、js文件和web服务中分别实现Hello World

x33g5p2x  于2021-12-14 转载在 其他  
字(0.5k)|赞(0)|评价(0)|浏览(226)

1.控制台中实现helloworld

2.js文件中实现helloworld

3.web服务中实现helloworld

4.nodejs上控制台上输出Hello Word返回undefined,什么原因?

1.控制台中实现helloworld

console.log('Hello World!');

2.js文件中实现helloworld

运行结果:


3.web服务中实现helloworld

var http = require('http');
http.createServer(function (request, response) {
 response.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
 response.write('Hello World');
 response.end();
}).listen(8080);
console.log('Server running at http://localhost:8080/');

运行结果:

4.nodejs上控制台上输出Hello Word返回undefined,什么原因?

因为返回值是undefined,属于正常情况

相关文章