expressjs cheat sheet
Expressjs is a npm package or we can say a web framework for nodejs. When we working on a node js-express js project we need several packages.
“npm install express” -> it will install the express js module inside the node project.
Let’s make a simple express js app.
When you are working on this app, every time when you make some changes into this app, you should also need to restart the server every time, for preventing this problem, you can use ‘nodemon’.
It's a kind of reloader for node js apps whenever you make some changes into an application. You can install this globally “npm install -g nodemon”
For installing this package locally inside node app: “npm i nodemon”
We can send json responses too.
We can send parameters via url
We can set optional parameter via url
We can set static files in the express app.
“app.use(express.static(“static”))”
We can add different routes inside index.js
We can make a POST request and get the body of the request.you can test via postman
—------------------------------------------------------------------------------------------------------------------------
express.js with mongodb - crud
First build the connection with mongodb
We can register/insert record via mongoose
Model
Login, Update, Patch & Delete
Password hashing in node js using bcrypt
Password salting adds a random string (the salt) to a password before hashing it. This way, the hash generated will always be different each time. Even if a hacker obtains the hashed password, it will take them a considerable amount of time to discover the original password that generated it.
File uploads in nodejs-expressjs