loading...

Node.js - Best Practices

edisonsanchez profile image Edison Sanchez ・1 min read

QUICK Creation

  1. Create a folder.
  2. Init Node Project.


    npm init

  3. Create app.js

    var express = require('express');
    

var app = express();

var port = process.env.PORT || 3000;

app.get('/', (req, rest) => {
rest.send('Welcome to my API!');
});

app.listen(port, () => {
console.log(Running on port ${port});
});



4. Install dependencies.
>

npm install express nodemon
npm install --save-dev eslint



5. Add script to package.json
>

...
"scripts": {
...
"start": "nodemon app.js",
"lint": "eslint .",
...
},
...
"nodemonConfig": {
"restartable": "rs",
"ignore": [
"node_modules/**/node_modules"
],
"delay": "2500",
"env": {
"NODE_ENV": "development",
"PORT": 4000
}
}
...



6. Configure ESLINT
>

npm run lint -- --init


Discussion

pic
Editor guide
 

For others really looking for best practices, here
github.com/goldbergyoni/nodebestpr...
It has +50k stars so pretty much covers a lot of goods

 

What exactly is the "best practice" you are advocating for in this post? The use of eslint?

 

I was curious if he mistakenly posted early, draft or something. So i looked into his past posts. There's another one on react which pretty much is a project structure that uses css in js.
dev.to/edisonsanchez/react-best-pr...

 

nodejs is much more than express 🤷‍♂️🤷‍♂️🤷‍♂️🤷‍♂️