快速了解nodejs,简单记录笔记

      我想利用自己时间了解nodejs作为后端的开发,同时自己的网易云部分,我打算内容部分,采用前端vue 来写。

      然后能实现简单的前后端处理。这是个基本想法,然后法师也是我认识比较有趣的人,现在他在弄nodejs 与 vue。刚好可以了解并向他学习。

     话不多说,安装后,下载lodash 模块。

npm i lodash --save -g

然后代码使用:

const _ = require('lodash')
const arr = _.concat([1,2],3)
console.log('arr...',arr)

输出结果:

arr... [ 1, 2, 3 ]

模块方式,a.js 使用 module.exports :

function add(a,b){
    return a+b
}

function mul(a,b){
    return a*b
}

module.exports = {
    add,
    mul
}

在b.js 获取出来

const {add,mul} = require('./a')

const sum = add(100,200)
const result = mul(100,200)

console.log(sum)
console.log(result)

输出结果:

300
20000

初识化工程文件:  

 npm init -y

会在对应的文件夹下产生

package.json

对应文件内容:

{
  "name": "testDebug",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

服务器请求:

const http = require('http')

const server = http.createServer((req,res) =>{
    res.writeHead(200,{'content-type':'text/html'})
    res.end('<h1>hello world</h1>')
})

server.listen(3000,() => {
    console.log('listening to 3000 port')
})

结果: 

 今天先了解这么多,后期希望自己越来越好,大家一起加油。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值