QUICK Creation
- Create a folder.
-
Init Node Project.
npm init
-
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
Latest comments (5)
This is a really a good and detailed article on best NodeJs project structure.
Here is a detaied guide on the different best practices which can be followed for any project: tatvasoft.com/blog/node-js-best-pr...
nodejs is much more than express 🤷♂️🤷♂️🤷♂️🤷♂️
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...