Home > Article > Web Front-end > Node.js first try cry
Check node version
[code]node -v
Create the first nodejs program
[code]helloWorld.js console.log("Hello World");
node
[code]> console.log('hello');
[code]var http = require('http'); http.createServer(function (request, response) { // 发送 HTTP 头部 // 状态码 200 // 内容类型 text/plain response.writeHead(200, { 'Content-Type' : 'text/plain'}); // 发送响应数据---浏览器输出 response.end('Hello World'); }).listen(8888); // 监听8888端口 // 终端输出 console.log('服务器监听8888端口')
Terminal operation:
[code]node server.js
Browser running:
[code]http://localhost:8888/server.js
##The above is the first try of Node.js Content, for more related content, please pay attention to the PHP Chinese website (www.php.cn)!