Home >Web Front-end >JS Tutorial >Make command line tools using Node.js
This time I will bring you the Notes on using Node.js to make command line tools and using Node.js to make command line toolsWhat are they? The following is a practical case. Let’s take a look.
This article introduces how to write a simple command line tool using Node.js and share it with everyone. The details are as follows:
The operating system needs to be Linux
1. Goal
Enter the command you wrote on the command line to complete the target task
Command line requirements are globally valid
Command line requirements You candelete
command line function, generate a file showing the current date
2. Code part
Create a new file and name it sherryFile
Contents of file sherryFile
Introduction: Generate a file with the current date and creator
#! /usr/bin/env node console.log('command start'); const fs = require('fs'); let date = new Date().toLocaleDateString(); let data = date + '\n\t' + '——create By karuru'; fs.writeFile('./date.txt', data, 'utf8', (err) => { if (err) { console.log('sherryFile command wrong', err); return false; } console.log('writeFile success!!!!'); console.log('command end'); });
Give the file execution permission chmod 755 sherryFile
Enter ./sherryFile
command startIn this file directory, a new date.txt file will be generated with the following contentwriteFile success!!!!
command end
2/28/2018Modify the command to be globally validcreate By karuru
ln sherryFile /usr/local/bin/sherryFileDelete command
rm /usr/local/bin/sherryFile
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on php Chinese website!
Recommended reading:
##readlineHow to read and write content line by lineDetailed explanation of the use of mutations and actions in VuexThe above is the detailed content of Make command line tools using Node.js. For more information, please follow other related articles on the PHP Chinese website!