THE BEGINNER’S GUIDE: Understanding Node.js & Express.js fundamentals
What is Node.js?
Node is an asynchronous event driven JavaScript runtime built upon Chrome’s V8 JavaScript engine. It’s designed to build scalable network applications.
That being the raw definition, let me clarify. Node.js enables you to write server side JavaScript. You may now be wondering, how? As you know, JavaScript is a language which runs in a browser. The browser’s engine takes JavaScript code and compiles it into commands. The creator of Node.js took Chrome’s engine and built a runtime for it to work on a server. Don’t get confused with the word runtime. It’s an environment where the language can get interpreted. So what do we have now? A way to write JavaScript on the back end.
- Install Node.js for your platform (MacOS, Windows or Linux)
- Initialize your project and link it to npm ->npm init -y
- Install Express in the myapp directory -> npm i express
- write this code
var express = require('express');
var app = express();app.get('/', function (req, res) {
res.send('Hello World!');
});app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});