Express JS is the goto framework for developing Web Applications
, APIs
and almost any kind of Backend
using Node.
To install express
, all you have to do is run the npm command
npm install express --save
And you're done.
create a file app.js
and add this code
// require express
var express = require('express');
var app = express();
// when "/" is opened in url, this function will be called.
app.get('/', function (req, res) {
res.json({ code: 200, message: 'success' });
})
app.listen( 3000, function () {
console.log('Express server running at http://localhost:3000');
});
node app.js
andhttp://localhost:3000
in web browser to see your newly created express server.It's also a good idea to install body-parser
and express-session
along with express
as most of the time you will want to read the data sent in POST
request and manage user sessions.