ubuntu 下 node.js 的使用

1 添加node.js命令

從官網 https://nodejs.org/en/ 下載linux 64位的包,然後解壓。

設置變量 export PATH=/user/local/node/bin:$PATH

在命令行下輸入node --version 可以看到已經可以正常使用

 

2  新建文件爲server.js

var http = require('http');

http.createServer

   (function(req,res){

    res.writeHeader(200, {"Content-Type": "text/plain"});   

          res.end("Hello oschina\n");   

).listen(3000,"127.0.0.1");

console.log('Server running at 3000');

 

運行node server.js

之後

訪問網頁http://127.0.0.1:3000/,可見結果

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章