DIY your own npm package.

purpose

test npm package DIY.

step by step

  1. create description file of npm package.

    You can use npm init to create the package.json.
    It will prompt you for values for the package.json fields.
    The two required fields are name and version. like this:

    mkdir mypkg; cd mypkg; npm init

  2. edit main js file 'index.js'

    exports.test = function() {
    console.log("This is a message from the mypkg package");
    }
    
  3. edit test script (optional)

    console.log('execute test script.')
    

    and then, you can make test: as follow:

    npm test

that's all about DIY your own npm moudule. 😃

usage

  1. Make a new directory outside of your project and cd into it,
    edit package.json , add dependency of your own package:

    cd ../; mkdir mytest; cd mytest;

    and then, edit package.json like this:

      "name": "my_test",
      "dependencies": {
        "mypkg": "file:../mypkg"
      } 
    }
    
  2. execute:

    npm install

    you can see output as follow:

     my_test@ /Users/changxun/Code/testdir
     └── mypkg@1.0.0 
    
     npm WARN xun_test@ No description
     npm WARN xun_test@ No repository field.
     npm WARN xun_test@ No license field.
    
posted @   changxun  阅读(148)  评论(0编辑  收藏  举报
编辑推荐:
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
· ASP.NET Core 模型验证消息的本地化新姿势
阅读排行:
· 从零开始开发一个 MCP Server!
· ThreeJs-16智慧城市项目(重磅以及未来发展ai)
· .NET 原生驾驭 AI 新基建实战系列(一):向量数据库的应用与畅想
· Ai满嘴顺口溜,想考研?浪费我几个小时
· Browser-use 详细介绍&使用文档
点击右上角即可分享
微信分享提示