Dates
Use date-fns. It is lighter than Moment.js. And it is immutable.
A word on ESlint
ESlint is probably the most popular linter for JavaScript. It is also very convenient and benefits from a large community. That is why I use it.
When I started using, I got confused by two different things: shareable configs and plugins. This thread explains the difference between the two quite well. Here is my version:
Plugins are like function definitions (a set of custom rules). Configs are like actual calls to thoses functions (pre-defined configuration of rules - like whether they're enabled or not, and how they are configured).
How to start a new JavaScript project?
If it is a simple project or a NPM package, I recommend having two distinct folders: src
for sources and dist
for builds.
-
Now, do:
git init git add remote origin ... # If need be npm init yarn add --dev babel-cli babel-preset-es2015 yarn add --dev eslint yarn add --dev eslint-config-standard \ eslint-plugin-standard \ eslint-plugin-promise \ eslint-plugin-import \ eslint-plugin-node
We use
babel
to transpile our code, to better support old versions of NodeJS.Regarding the last line, the config eslint-config-standard sets the configuration of these four plugins:
standard
,promise
,import
andnode
. That is why we need to install them alongside the shareable config. Of course it is a config foreslint
, that is why we installed it on the previous line. -
Do:
yarn add prettier-eslint-cli
Normally,
prettier-eslint
only operates on strings, not on files.prettier-eslint-cli
will provide you with a command to applyprettier-eslint
on files.What is
prettier-eslint
meant for? Well, under the hood it callsprettier
(probably the best JavaScript formatter to date) and theneslint --fix
to format your code. Twice. But there's a reason for that.Now we need to configure
eslint
to tell it to use standard as its style. -
To use the standard style with ESlint, create
.eslint
in the root directory of your project and write:{ "extends": "standard" }
-
Add a badge to your
README.md
: badge.fury.io/for/js -
Configure
package.json
:..., "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "babel src --presets babel-preset-es2015 --out-dir dist", "format": "prettier-eslint \"src/*.js\"", "lint": "eslint src", "check": "npm run lint && npm run test" }, ...
All set!
Resources
NodeJS
- Node.js ES2015/ES6, ES2016 and ES2017 support
- Node js comme les grands (Romain Maton)
- Node.js Best Practices
Set-up your environment
Documentation
General
- Dans cette jungle de l’outillage JavaScript, un retour à la simplicité est-... (Hubert SABLONNIÈRE)
- 30 seconds of code
- Clean Code concepts adapted for JavaScript
- A different way of understanding this in JavaScript
- JavaScript Equality Table
- How JavaScript Works
- The Linux Foundation Unites JavaScript Community for Open Web Development
- How it feels to learn JavaScript in 2016
- ES6 Overview in 350 Bullet Points
- Programming JavaScript Applications (book)
- Composition over Inheritance
- Learning JavaScript Design Patterns (book)
- Want to learn JavaScript in 2015 / 2016?
- You Don't Know JS (book series)
- 12 Rules for Professional JavaScript in 2015
- 10 bonnes pratiques JavaScript
- A Deeper Look at Objects in JavaScript
- 10 Interview Questions Every JavaScript Developer Should Know
- JavaScript: an acceptable use of double-equals? Just.
- Un gros Troll de plus sur Javascript
- Some really good best practices from Airbnb
- DevFest Nantes 2015 - Découvrir ES6 par le code
- Top 10 ES6 Features Every Busy JavaScript Developer Must Know
- ES6/ES2015 en 24 jours
- Must See JavaScript Dev Tools That Put Other Dev Tools to Shame
- You Don't Need jQuery
- How to Schedule Background Tasks in JavaScript
- INTRODUCING QUEUES IN NODE.JS
- https://github.com/k33g/files/tree/master/javascript
- ES6 const is not about immutability
- ECMAScript 2017: the final feature set
- Emojis in Javascript
- Transpiling dependencies with Babel
- Running a Node.js process on Debian as a Systemd Service
- The Cost Of JavaScript
- JavaScript hacks for ES6 hipsters
- The Vanilla JavaScript Toolkit
- [Arrow Functions in Class Properties Might Not Be As Great As We Think](https://medium.com/@charpeni/arrow-functions-in-class-properties-might-not-be-as-great-as-we-think-3b3551c440b1
- ECMA-262-3 in detail. Chapter 8. Evaluation strategy.
export default thing
is different toexport { thing as default }
- In JS functions, the 'last' return wins
Some cool node/npm stuff/packages/tools
- How to Become a Better Node.js Developer in 2016
- 10 Habits of a Happy Node Hacker (2016)
- node-startup: startup script for Linux-based systems for running node app when rebooting using an /etc/init.d script
- peerflix
- nodegit: manipulating git repositories with Node.js
- How to Use npm as a Build Tool
- Start your own JavaScript library using webpack and ES6
- Livedown
- Sequelize: a promise-based ORM for Node.js (PostgreSQL, MySQL, MariaDB, SQLite and MSSQL) + Epilogue: create flexible REST endpoints and controllers from Sequelize models in your Express app
Closures
In loops, they are a common issue. Here is how to solve it: