Published 2022-03-31

Node.js - First Program & REPL

First Program

创建hellowrold.js,打开控制台执行node helloworld.js

console.log('hello world')

// hello world

基于http创建一个简单 server

一个简单nodejs server程序包含三个必备条件

引入依赖包

const http = require('http')

创建 server

const http = require('http')

http
  .createServer(function (req, res) {
    response.writeHead(200, {'Content-Type': 'text/plain'})
    response.end('Hello World\n')
  })
  .listen(8888)

console.log('Server running at http://127.0.0.1:8888/')

启动 server

node server.js
#Server running at http://127.0.0.1:8888/

进入 REPL(交互解释器)模式

REPEL 即交互解释器,使用单个表达式作为用户输入,并在执行后将结果返回到控制台

node

LV2DBj

使用tab显示当前输入对象的扩展,比如输入Number.后按下tab

lOfZTD