2017-07-17 2 views
1

Zum Beispiel API (Strecke) zu CLI konvertieren: Ich habe eine Route wie folgt aus:Wie auf Express.js

http://localhost:3000/source1/test 

jetzt will ich es laufen:

Wie kann ich TU es?

Antwort

1

Wir können mit Modul tun:

command-line-args

const commandLineArgs = require('command-line-args'); 
const optionDefinitions = [ 
    {name: 'route', alias: 'r', type: String} 
]; 
const option = commandLineArgs(optionDefinitions); 

Dann können wir das Schaltergehäuse verwenden, um die Funktion, die wir tun wollen. Allerdings müssen wir alle API mit ihrem Parameter in normale Funktion konvertieren.