text 如何制作nodejs api模块

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 如何制作nodejs api模块相关的知识,希望对你有一定的参考价值。

// use express-generator(optional)

//잡지식
* express -h (사용법)
* Ctrl+D (동시 셀렉트)
* var -> let, ; delete (optional)

//express install
npm i express-generator
express app
cd myapp
npm install (필요 npm 자동 설치 (essential))
npm install body-parser

// make module

1. make 'lib' forder under myapp
2. make module script(example->calculator.js) under lib forder
3. connect app.js with module script

app.js

let cal = require('./lib/calculator')
console.log(cal.test.sum(1,2))
console.log(cal.test.avg(1,2))

calculator.js

let test = {
  sum:function(a, b){
    return a+b
    },
  avg:function(a, b){
    return test.sum(a,b)/2
    }
  }
  
  module.exports.test = test

// make npm api
https://docs.npmjs.com/creating-node-js-modules


以上是关于text 如何制作nodejs api模块的主要内容,如果未能解决你的问题,请参考以下文章

如何要求深度嵌套的 NodeJS 模块?

如何创建 NodeJS 模块?

nodejs中标准包的制作,上传,安装及卸载方法

NodeJS:如何修复不同的节点模块版本? [复制]

如何在 reactjs 中向 nodejs RESTful API 发出 POST 请求

nodejs入门API之net模块