NodeJS学习日报day4——模块化
// console.log(module); // 执行顺序不同,结果也不同
// module.exports = {
// name : 'Cra2iTeT',
// hi() {
// console.log('hi');
// }
// } // 挂在userName属性
module.exports.userName = '张三' module.exports.hello = function() {
console.log('hello');
} module.exports = {
name : 'Cra2iTeT',
hi() {
console.log('hi');
}
}
const http = require('http')
const fs = require('fs')
const path = require('path')
const server = http.createServer()
server.on('request', (req, resp) => {
const url = req.url
const fPath = path.join(__dirname, '../day2', url)
console.log(fPath);
fs.readFile(fPath, 'utf-8', function(err, dataStr) {
if (err) {
console.log("404 not found" + err.message);
}
// 加上响应头以后css样式无法显示
// resp.setHeader('Content-Type', 'text/html; charset=utf-8')
resp.end(dataStr)
})
})
// server.on('request', (req, resp) => {
// const url = req.url
// let fPath = ''
// if (url === '/' || url === '/clock/index.html' || url === '') {
// fPath = path.join(__dirname, '../day2', '/clock/index.html')
// } else {
// fPath = path.join(__dirname, '../day2', url)
// }
// console.log(fPath);
// fs.readFile(fPath, 'utf-8', function(err, dataStr) {
// if (err) {
// console.log("404 not found " + err.message);
// }
// // 加上响应头以后css样式无法显示
// // resp.setHeader('Content-Type', 'text/html; charset=utf-8')
// resp.end(dataStr)
// })
// })
server.listen(8080, () => {
console.log('server running at http://127.0.0.1:8080');
})
const http = require('http')
const server = http.createServer()
server.on('request', (req, resp) => {
const url = req.url
let content = '<h1>404 not found</h1>'
if (url === '/' || url === '/index.html') {
content = '<h1>首页</h1>'
} else if (url === '/about.html') {
content = '<h1>关于页面</h1>'
}
resp.setHeader('Content-Type', 'text/html; charset=utf-8')
resp.end(content)
})
server.listen(8080, () => {
console.log('server running at http://127.0.0.1:8080');
})
NodeJS学习日报day4——模块化的更多相关文章
- NodeJs学习日报day8——接口编写
今天看了黑马NodeJs中关于接口编写以及跨域问题的视频
- NodeJs学习日报day9——操作数据库
const mysql = require('mysql') const db = mysql.createPool({ // 数据库的ip地址 host: 'localhost', user: 'r ...
- NodeJs学习日报day7——简单中间件
const express = require('express') const app = express() const mw = function(req, resp, next) { cons ...
- NodeJs学习日报day6——路由模块
const express = require('express') const app = express() app.get('/user', function(req, resp) { resp ...
- NodeJs学习日报day5——导入模块
const { match } = require("assert") function dateFormat(dataStr) { const dt = new Date(dat ...
- NodeJs学习日报——day3
// 导入模块 const http = require('http') // 创建web服务器实例 const server = http.createServer() // 为服务器实例绑定req ...
- Nodejs学习路线图
前言 用Nodejs已经1年有余,陆陆续续写了48篇关于Nodejs的博客文章,用过的包有上百个.和所有人一样,我也从Web开发开始,然后到包管 理,再到应用系统的开发,最后开源自己的Nodejs项目 ...
- nodeJs学习路线
转载自:http://blog.fens.me/nodejs-roadmap/ 前言 用Nodejs已经1年有余,陆陆续续写了48篇关于Nodejs的博客文章,用过的包有上百个. 和全部人一样,我也从 ...
- Nodejs学习笔记(四)——支持Mongodb
前言:回顾前面零零碎碎写的三篇挂着Nodejs学习笔记的文章,着实有点名不副实,当然,这篇可能还是要继续走着离主线越走越远的路子,从简短的介绍什么是Nodejs,到如何寻找一个可以调试的Nodejs ...
随机推荐
- github:git clone下载加速以及vim-plug下载插件加速
git clone 下载加速 1. 先在github将仓库地址复制下来 2. git clone时将https://github.com/* 改为https://gitclone.com/github ...
- 互联网前沿技术——01 找不到模块“lodash”
检查安装 node --version 修改 安装:npm install 启动:grunt server 如果报错: 找不到模块"lodash" https://www.soin ...
- Mybatis传递参数的几种方式
使用Map传递 优点:直接在sql中取出key即可 缺点:适用于小项目,不符合大公司规范 对象传递参数 优点:符合标准规范 缺点:麻烦 3.只有一个基本类型参数的情况下,直接在sql中取中 4.多个参 ...
- office online在线预览服务与https的tls证书兼容问题
问题现象:k8s环境配置证书后,无法调用office online 服务,附件无法预览 问题原因:ingress默认启用得是tls1.2,不兼容以下版本 k8s环境解决方法:增加ingress配置,兼 ...
- ArcGIS Server 禁用/rest/services路径(禁用服务目录)
ArcGIS Server服务目录(路径如:http://<hostname>:6080/arcgis/rest/services)默认可以不需要登陆直接打开.效果如下图. ArcGIS服 ...
- [转载]Linux后门整理合集(脉搏推荐)
我在思考要不要联系下....都禁止转载了.... 简介 利用 Unix/Linux 自带的 Bash 和 Crond 实现远控功能,保持反弹上线到公网机器. 利用方法 先创建 /etc/xxxx 脚本 ...
- 『忘了再学』Shell基础 — 3、echo命令的介绍与使用
目录 1.echo命令的作用 2.echo命令的基本用法 3.echo命令的-e选项用法 4.echo命令一些特殊用法 (1)输出字符带有字体颜色 (2)输出字符带有背景颜色 在讲Shell脚本之前, ...
- vue Cannot read property ‘tapPromise‘ of undefined
https://blog.csdn.net/qq379682421/article/details/111574290 https://github.com/SimenB/add-asset-html ...
- 比较一下 Java 和 JavaSciprt?
JavaScript 与 Java 是两个公司开发的不同的两个产品.Java 是原 Sun Microsystems 公司推出的面向对象的程序设计语言,特别适合于互联网应用程序 开发:而 JavaSc ...
- mysql的cpu飙升原因及处理
Mysql 批量杀死进程 正常情况下kill id,即可,但是有时候某一异常连接特别多的时候如此操作会让人抓狂,下面记录下小方法: use information_schema; select co ...