处理get与post请求示例代码:

const http = require('http');
const querystring = require('querystring'); const server = http.createServer((req,res) => {
const method = req.method;
const url = req.url;
const path = url.split('?')[0];
const query = querystring.parse(url.split('?')[1]); // 设置返回格式为json
res.setHeader('Content-type','application/json'); // 返回的数据
const resData = {
method,
url,
path,
query
} if(method === 'GET') {
res.end(JSON.stringify(resData));
}
if(method === 'POST') {
let postData = '';
req.on('data',chunk => {
postData += chunk.toString();
}) req.on('end', () => {
resData.postData = postData;
res.end(JSON.stringify(resData));
})
}
}) server.listen(8000,() => {
console.log('listening on 8000 port');
}) console.log('ok');

Node.js开发博客项目笔记-http请求处理(1)的更多相关文章

  1. node.js开发博客系统---前端项目搭建(一)

    Express: https://github.com/petecoop/generator-express 安装node.js和npm 执行: npm install -g yo npm insta ...

  2. Node.js开发博客系统

    数据库设计 用户表: id phone password nickname head_img personal_sign level_id create_time update_time is_del ...

  3. node.js 开发博客系统

    1. 安装yoman :npm install -g yo 2. 安装 generator-express :npm install -g generator-express 3. 安装 bower ...

  4. 基于.NetCore开发博客项目 StarBlog - (5) 开始搭建Web项目

    系列文章 基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客? 基于.NetCore开发博客项目 StarBlog - (2) 环境准备和创建项目 基于.NetC ...

  5. 基于.NetCore开发博客项目 StarBlog - (4) markdown博客批量导入

    系列文章 基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客? 基于.NetCore开发博客项目 StarBlog - (2) 环境准备和创建项目 基于.NetC ...

  6. 基于.NetCore开发博客项目 StarBlog - (8) 分类层级结构展示

    系列文章 基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客? 基于.NetCore开发博客项目 StarBlog - (2) 环境准备和创建项目 基于.NetC ...

  7. 基于.NetCore开发博客项目 StarBlog - (14) 实现主题切换功能

    系列文章 基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客? 基于.NetCore开发博客项目 StarBlog - (2) 环境准备和创建项目 基于.NetC ...

  8. 基于 abp vNext 和 .NET Core 开发博客项目 - Blazor 实战系列(一)

    系列文章 基于 abp vNext 和 .NET Core 开发博客项目 - 使用 abp cli 搭建项目 基于 abp vNext 和 .NET Core 开发博客项目 - 给项目瘦身,让它跑起来 ...

  9. 基于 abp vNext 和 .NET Core 开发博客项目 - Blazor 实战系列(二)

    系列文章 基于 abp vNext 和 .NET Core 开发博客项目 - 使用 abp cli 搭建项目 基于 abp vNext 和 .NET Core 开发博客项目 - 给项目瘦身,让它跑起来 ...

  10. 基于 abp vNext 和 .NET Core 开发博客项目 - Blazor 实战系列(五)

    系列文章 基于 abp vNext 和 .NET Core 开发博客项目 - 使用 abp cli 搭建项目 基于 abp vNext 和 .NET Core 开发博客项目 - 给项目瘦身,让它跑起来 ...

随机推荐

  1. useCookie函数:管理SSR环境下的Cookie

    title: useCookie函数:管理SSR环境下的Cookie date: 2024/7/13 updated: 2024/7/13 author: cmdragon excerpt: 摘要:本 ...

  2. tp5命名规范

    tp5中对类,文件名,函数和方法的命名规范如下: 类名和类文件名保持一致,并统一采用驼峰法命名(首字母大写) 类的命名采用驼峰法,并且首字母大写,例如 User.UserType,不需要添加contr ...

  3. 从基础到高级应用,详解用Python实现容器化和微服务架构

    本文分享自华为云社区<Python微服务与容器化实践详解[从基础到高级应用]>,作者: 柠檬味拥抱. Python中的容器化和微服务架构实践 在现代软件开发中,容器化和微服务架构已经成为主 ...

  4. oeasy 教您玩转linux 之 010209 装酷利器 hollywood

    我们来回顾一下 上一部分我们都讲了什么? 屏幕故障风格的软件包bb 可以设置音频 这次装一个酷 下个hollywood软件包 apt show hollywood apt search hollywo ...

  5. njs最详细的入门手册:Nginx JavaScript Engine

    原文链接:https://hi.imzlh.top/2024/07/08.cgi 关于njs 首先,njs似乎在国内外都不受关注,资料什么的只有 官网参考手册,出了个问题只能看到Github Issu ...

  6. GitHub Star 数量前 12 的开源无代码工具

    相关文章:GitHub Star 数量前 15 的开源低代码项目 在本篇文章中,我们将探索 12 款在 GitHub 上星级排名前列的开源无代码工具. 每款工具都旨在简化和加速开发过程,但各自侧重于不 ...

  7. C#实现单例模式的6种方法

    介绍 单例模式是软件工程学中最富盛名的设计模式之一.从本质上看,单例模式只允许被其自身实例化一次,且向外部提供了一个访问该实例的接口.通常来说,单例对象进行实例化时一般不带参数,因为如果不同的实例化请 ...

  8. 顺序表_C

    // Code file created by C Code Develop #include "ccd.h" #include "stdio.h" #incl ...

  9. Odoo 增加web后端的响应能力

    实践环境 Odoo 14.0-20221212 (Community Edition) web_responsive-14.0.1.2.1.zip https://apps.odoo.com/apps ...

  10. mybatis源码分析:Mapper接口是什么

    在<mybatis源码分析:启动过程>中分析了mybatis的启动过程,mybatis的启动过程主要集中在解析其核心配置文件(mybatis-config.xml)上,把配置文件中的配置全 ...