Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $YECBGYFECGEAFWHA as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2

Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $BBWFDDBHHYHDXXAB as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2
Linux中怎么用Node.js写一个命令行工具_创想鸟

Linux中怎么用Node.js写一个命令行工具

1. 目标

在命令行输入自己写的命令,完成目标任务

命令行要求全局有效

命令行要求可以删除

命令行作用,生成一个文件,显示当前的日期

2. 代码部分

新建一个文件,命名为sherryFile

文件sherryFile的内容

介绍: 生成一个文件,文件内容为当前日期和创建者

#! /usr/bin/env nodeconsole.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');});

给该文件赋予执行权限chmod 755 sherryFile

在该文件所在的文件路径下输入./sherryFile

如果输出以下内容,表示命令执行成功

command start
writeFile success!!!!
command end

在该文件目录下,会有一个新的date.txt文件生成,内容如下

2/28/2018
    create By karuru

将命令修改为全局有效

ln sherryFile /usr/local/bin/sherryFile

删除命令

rm /usr/local/bin/sherryFile

以上就是Linux中怎么用Node.js写一个命令行工具的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/128332.html

赞 (0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
win10怎么清除文件资源管理器历史记录_文件资源管理器历史记录清除步骤
上一篇 2025年11月27日 22:58:55
iPhone使用iTunes刷机恢复提示无法更新, 发生未知的错误 (1110)的解决办法分享!
下一篇 2025年11月27日 23:00:57

相关推荐

发表回复

登录后才能评论
关注微信