我想利用自己时间了解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')
})
结果:
今天先了解这么多,后期希望自己越来越好,大家一起加油。