work hard work smart

专注于Java后端开发。 不断总结,举一反三。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2022年2月18日

摘要: Nodejs中的函数与JavaScript类似。 匿名函数:samp11.js function execute(someFunction, value) { someFunction(value); } execute(function(word){ console.log(word) }, "H 阅读全文

posted @ 2022-02-18 15:54 work hard work smart 阅读(38) 评论(0) 推荐(0) 编辑

摘要: 创建模块 hello.js exports.world = function(){ console.log("hello world"); } 引入模块samp9.js var hello = require("./hello"); hello.world(); 执行 PS E:\study\nod 阅读全文

posted @ 2022-02-18 15:45 work hard work smart 阅读(20) 评论(0) 推荐(0) 编辑

摘要: 1、从流中读取数据 samp7.js var fs = require("fs"); var data = ''; // 创建可读流 var readerStream = fs.createReadStream('input.txt'); // 设置编码为 utf8 readerStream.set 阅读全文

posted @ 2022-02-18 15:21 work hard work smart 阅读(24) 评论(0) 推荐(0) 编辑

摘要: 1、阻塞代码 创建文件input.txt, 内容为 hello world in input.txt 创建samp3.js var fs = require("fs"); var data = fs.readFileSync('input.txt'); console.log(data.toStri 阅读全文

posted @ 2022-02-18 14:07 work hard work smart 阅读(29) 评论(0) 推荐(0) 编辑

摘要: 一、创建samp1.js 内容如下: console.log("Hello World"); 运行结果: PS E:\study\nodejs\demo1> node .\samp1.js Hello World 二、创建第一个应用 创建samp2.js var http = require("ht 阅读全文

posted @ 2022-02-18 13:03 work hard work smart 阅读(50) 评论(0) 推荐(0) 编辑