import { format, formatDistance, formatRelative, subDays } from 'date-fns'
format(new Date(), '[Today is a] dddd')
//=> "Today is a Wednesday"
formatDistance(subDays(new Date(), 3), new Date())
//=> "3 days ago"
formatRelative(subDays(new Date(), 3), new Date())
//=> "last Friday at 7:26 p.m."
const mkdirp = require('mkdirp')
// return value is a Promise resolving to the first directory created
mkdirp('/tmp/foo/bar/baz').then(made =>
console.log(`made directories, starting with ${made}`));
const glob = require("glob");
// options is optional
glob("**/*.js", options, function (er, files) {
// files is an array of filenames.
// If the `nonull` option is set, and nothing
// was found, then files is ["**/*.js"]
// er is an error object or null.
});
很久以前,软件工程师意识到他们可以通过消除在每个应用程序中一遍又一遍地编写重复代码的需要来显着加快开发过程。Node.js 应用程序受益于 NPM 包注册表中提供的超过一百万个开源包。 最流行的软件包每周下载量超过 1000 万次,是许多应用程序的基础,从小型宠物项目到知名科技初创公司。 今天,现代 Web 应用程序中 97% 的代码来自 npm 模块。
我们遴选了30个常用的nodejs安装包,让您免于重新发明轮子。
一、实用功能
1. Async
2.rxjs
4.Underscore.js
5.day.js
6.Ramda
9.Lodash
10.date-fns
11.uuid
操作文件系统
1.fs-extra
二、Web框架
1. express
2. koa
3. Fastify
Fastify是最快的可扩展 Web 框架之一,专注于以最少的开销提供最佳的开发人员体验。
4. socket.io
三、改进开发过程
1. typescript
DB_HOST=localhost DB_USER=root DB_PASS=s1mpl3 require('dotenv').config(); const db = require('db'); db.connect({ host: process.env.DB_HOST, username: process.env.DB_USER, password: process.env.DB_PASS });