2021-07-11 15:42:56 +02:00
|
|
|
---
|
|
|
|
id: node-api
|
|
|
|
title: "Node API"
|
|
|
|
---
|
|
|
|
|
|
|
|
Verdaccio can be invoked programmatically. The Node API was introduced after version `verdaccio@3.0.0`.
|
|
|
|
|
2021-07-27 21:52:49 +02:00
|
|
|
## Usage {#usage}
|
2021-07-11 15:42:56 +02:00
|
|
|
|
2021-07-27 21:52:49 +02:00
|
|
|
#### Programmatically {#programmatically}
|
2021-07-11 15:42:56 +02:00
|
|
|
|
|
|
|
```js
|
2022-03-04 19:22:02 +01:00
|
|
|
const startServer = require("verdaccio").default;
|
|
|
|
|
|
|
|
let config = {
|
|
|
|
storage: "./storage",
|
|
|
|
auth: {
|
|
|
|
htpasswd: {
|
|
|
|
file: "./htpasswd"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
uplinks: {
|
|
|
|
npmjs: {
|
|
|
|
url: "https://registry.npmjs.org/",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
self_path: "./",
|
|
|
|
packages: {
|
|
|
|
"@*/*": {
|
|
|
|
access: "$all",
|
|
|
|
publish: "$authenticated",
|
|
|
|
proxy: "npmjs",
|
|
|
|
},
|
|
|
|
"**": {
|
|
|
|
proxy: "npmjs"
|
|
|
|
}
|
|
|
|
},
|
2022-03-28 20:02:08 +02:00
|
|
|
log: {
|
2022-03-04 19:22:02 +01:00
|
|
|
type: "stdout",
|
|
|
|
format: "pretty",
|
|
|
|
level: "http",
|
2022-03-28 20:02:08 +02:00
|
|
|
};
|
2022-03-04 19:22:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
startServer(
|
|
|
|
config,
|
|
|
|
6000,
|
|
|
|
undefined,
|
|
|
|
"1.0.0",
|
|
|
|
"verdaccio",
|
|
|
|
(webServer, addrs) => {
|
|
|
|
webServer.listen(
|
|
|
|
addrs.port || addrs.path,
|
|
|
|
addrs.host,
|
|
|
|
() => {
|
|
|
|
console.log(`verdaccio running on : ${addrs.host}:${addrs.port}`);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
2021-07-11 15:42:56 +02:00
|
|
|
```
|
|
|
|
|
2021-07-27 21:52:49 +02:00
|
|
|
## Other implementations {#other-implementations}
|
2021-07-11 15:42:56 +02:00
|
|
|
|
|
|
|
* [verdaccio-server](https://github.com/boringame/verdaccio-server) local npm registry proxy server
|
|
|
|
|
|
|
|
```js
|
|
|
|
// js
|
|
|
|
import * as verdaccioServer from "verdaccio-server";
|
|
|
|
verdaccioServer.start();
|
|
|
|
verdaccioServer.stop();
|
|
|
|
verdaccioServer.list();
|
|
|
|
verdaccioServer.stopAll();
|
|
|
|
verdaccioServer.show();
|
|
|
|
verdaccioServer.cli();
|
|
|
|
// windows .net2
|
|
|
|
verdaccioServer.serviceInstall();
|
|
|
|
verdaccioServer.serviceUninstall();
|
|
|
|
verdaccioServer.serviceStart();
|
|
|
|
verdaccioServer.serviceStop();
|
|
|
|
verdaccioServer.serviceRestart();
|
|
|
|
```
|