# NodeJs 面试题 1. 当一个Js function被调用时,将会被放在那里? A. the call stack (调用栈) B. the event loop (事件循环) C. the poll phase (调查阶段) D. the events queue (事件队列) 2. 你能通过Node.js创建一个https web server吗? A. 不能,目前还没有包支持 B. 可以,通过使用 https 或 Http2 模块 C. 可以,通过 path 模块 D. 可以,通过 http 模块 3. 你如何通过Node获得CPU的数量? A. node -p "process.cpus" B. node -p "util.cpus().size" C. node -p "process.os.cpus" D. node -p "os.cpus().length" 4. 下列哪项Object是stream(流)? A.process.uptime B.process.stdout C.process D.Buffer 5. 下列哪个module variable为目前module的绝对路径? A. __pathname B. __location C. __flder D.__filename 6. 当你在Node.js运行Javascript时,下列哪个在Node.js堆中的元件实际运行Javascript? A.the libuv library B.the c-ares library C.the VM (like VS or Chakra) D.the repl module 7. 下列代码在输出为? ```javascript= const http = require('http'); const hostname = '127.0.0.1'; const port = 3000; const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader("Content-Type", "text/plain"); res.end("Hello World\n"); }); server.listen(port, hostname, () => { console.log(`server running at http://${hostname}:${port}/`); }); ``` A. server running at http://localhost:3000/ B. server running at port 3000 C. server running at http://localhost:4000/ D. server running at http://127.0.0.1:3000/ 8. 下面代码的作用是什么? ```javascript= const fs = require('fs'); const os = require('os'); const system = os.platform(); const user = os.userInfo().username; fs.appendFile('hello.txt', `Hello ${user} on ${system}`, (err) => { if (err) throw err; console.log('The data was appended to file!');} ); ``` A. 创建一个文件 hello.txt,并在后面添加自定义文本 B. 创建一个图片文件 C. 在终端打印系统信息 D. 创建一个命名数据并添加数字 9. 如何运行一个node程序, 如果入口文件为index.js A. nodemon start B. start index.js C. node index.js D. node start 10. 什么是Node LTS 版本? A. 不稳定版本,避免使用 B. 即将失效版本 C. 拥有最新特性的版本 D. 安全并长期支持的版本 11. 下列哪项在事件触发器(event emitter)中不是合法的方法? A. start B. on C. once D. off 12. 以.node结尾的文件代表什么? A. `C++`文件可以以.node文件结尾,Node可以直接运行。 B. `C++`插件,通过node-gyp编译 C. `JSON`文件,等同于.json结尾的文件 D. `Js`文件,等同于.js结尾的文件 13. 哪一条加载一个以promise为基础的readFile方法? A.`const { readFile } = require(fs).promises` B.`const { readFile } = require(fs)` C.`const { readFilePromises: readFile } = require(fs)` D.`const { readFile } = require(promises)` 14. fs 模块的目的是? A. 提供基础的功能用于request和response B. 提供基础的功能用于文件操作 C. 提供基础的功能用于数据库操作 D. 提供基础的功能用于查找文件系统 15. 哪一个Node核心模块包裹在OpenSSL模块外? A.SSL B.hash C.crypto D.TLS