第一个服务器端的node.js
1. 首先打开node终端
> var http = require('http');
undefined
> http.createServer(function (req, res) {
... res.writeHead(200, {'Content-Type': 'text/plain'});
... res.end('Hello Shengtai\n');
... }).listen(8124, "127.0.0.1");
{ domain:
{ domain: null,
_events: { error: [Function] },
_maxListeners: undefined,
members: [] },
_events:
{ request: [Function],
connection: [Function: connectionListener],
clientError: [Function] },
_maxListeners: undefined,
_connections: 0,
_handle: null,
_usingSlaves: false,
_slaves: [],
allowHalfOpen: true,
pauseOnConnect: false,
httpAllowHalfOpen: false,
timeout: 120000 }
> console.lgo('Server running at http://127.0.0.1:8124/');
TypeError: undefined is not a function
at repl:1:9
at REPLServer.defaultEval (repl.js:132:27)
at bound (domain.js:254:14)
at REPLServer.runBound [as eval] (domain.js:267:12)
at REPLServer.<anonymous> (repl.js:279:12)
at REPLServer.emit (events.js:107:17)
at REPLServer.Interface._onLine (readline.js:214:10)
at REPLServer.Interface._line (readline.js:553:8)
at REPLServer.Interface._ttyWrite (readline.js:830:14)
at ReadStream.onkeypress (readline.js:109:10)
> console.log('Server running at http://127.0.0.1:8124/');
Server running at http://127.0.0.1:8124/
undefined
>
2. 其次打开浏览器输入http://localhost:8124/
3. 最后可以看到结果: Hello Shengtai
浙公网安备 33010602011771号