2015年2月24日 星期二

node.js : send_get_html

index.html

============

<!doctype html>
<html>
<heed>
    <title>Socket.IO chat</title>
    <style>
      * { margin: 0; padding: 0; box-sizing: border-box; }
      body { font: 13px Helvetica, Arial; }
      form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
      form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
      form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
      #messages { list-style-type: none; margin: 0; padding: 0; }
      #messages li { padding: 5px 10px; }
      #messages li:nth-child(odd) { background: #eee; }
    </style>
  </head>
  <body>

   <ul id="messages"></ul>
    <form action="">
      <input id="m" autocomplete="off" /><button>Send</button>
    </form>
  </body>
</html>


=============

index.js

==============
var app=require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);

app.get('/', function(req, res){
  res.sendfile(__dirname +'/index.html');
});

io.on('connection', function(socket){
  console.log('a user connected');
});

http.listen(3000, function(){
  console.log('listening on *:3000');
});


=============

[peterchang@localhost node_modules]$ node index
listening on *:3000



















node.js express / hello word

app.js

///////////////////////////////////////////////////////////////
s = require('express')
var app = express()

app.get('/', function (req, res) {
  res.send('Hello World!')
})

var server = app.listen(3000, function () {

  var host = server.address().address
  var port = server.address().port

  console.log('Example app listening at http://%s:%s', host, port)

})

///////////////////////////////////////////////////////////////
in lunix 

^C[peterchang@localhost node_modules]$ ls
app.js  express

[peterchang@localhost node_modules]$ node  app.js


///////////////////////////////////////////////////////////////


vi

To Start vi


*vi filenameedit filename starting at line 1
vi -r filenamerecover filename that was being edited when system crashed



To Exit vi

whenever a colon (:) is typed.

*:x<Return>quit vi, writing out modified file to file named in original invocation
:wq<Return>quit vi, writing out modified file to file named in original invocation
:q<Return>quit (or exit) vi
*:q!<Return>quit vi even though latest changes have not been saved for this vi call