nodejs02---demo

來源:互聯網
上載者:User

標籤:dos   nodejs   修改   viso   返回   module   mod   文字編輯器   調試   

1.Hello World    打一個一個文字編輯器,在其中輸入        console.log(‘Hello World‘);    並儲存為helloworld.js。開啟dos視窗進入該檔案的目錄運行    node helloworld.js  執行則可以看到輸出的helloworld2.Node.js命令列工具    node  -v  版本    node -e      eval scipt    eval(“console.log(‘呵呵‘)”);     例:node -e "console.log(‘hello world‘)";   直接執行        3. node :直接進入編譯模式    然後輸入:    console.log("111")        第一行是輸出、第二行是傳回值4.建立HTTP伺服器    建立一個app.js         var http=require(‘http‘)   //引入http包拿到http對象,模組和包沒有明顯的區分,http.createServer(function(req,res){  //調用對象的方法    res.writeHead(200,{‘Content-Type‘:‘text/html‘});    res.write(‘<h1>Node.js</h1>‘);    res.end(‘<p>PCAT</p>‘);}).listen(3000);console.log(‘HTTP server is listening at port 3000.‘);接下來node  app.js   開啟瀏覽器訪問  http://localhost:3000即可。這樣就部署了一個web。比如tomcat、resin更加方便4.調試代碼:下載最新版node,進入node安裝目錄C:\Program Files (x86)\nodejs\node_modules\npm,執行npm install -supervisor -g 安裝supervisor包來控制調試代碼。 (未完成)  進入編譯模式:node 執行:supervisor app.js代碼改動重新整理頁面就修改了, 不需要每次停止重啟node.js的服務 

app.js

var http=require(‘http‘)//引入http包拿到http對象,模組和包沒有明顯的區分,http.createServer(function(req,res){//調用對象的方法,回調    res.writeHead(200,{‘Content-Type‘:‘text/html‘});    res.write(‘<h1>Node.js</h1>‘);    res.end(‘<p>PCAT</p>‘);}).listen(3000);console.log(‘HTTP server is listening at port 3000.‘);

helloworld.js

console.log("Hello word愛愛愛");

 

nodejs02---demo

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.