Working with Nodejs
Step 1: Run the following command in the terminal to verify if the node.js is installed. This command will show the installed version of NodeJs to our system.
node --version
Step 2: Initialize the node project.
npm init -y
Step 3: Install the necessary packages/libraries in your project using the following commands.
npm install express --save
Project Structure:
The updated dependencies in package.json file will look like:
"dependencies": {
"express": "^4.19.2",
}
Example: Implementation to show the use setting up the server.
// app.js
const express = require('express');
const app = express();
const port = 5000;
// Handing the route to the server
app.get('/', function (req, res) {
res.send('Welcome to w3wiki Article');
});
// Starting server using listen function
app.listen(port, function (err) {
if (err) {
console.log("Error!!!");
}
else {
console.log("Server is running at port " + port);
}
});
Step to Run Application: Run the application using the following command from the root directory of the project
node app.js
Output:
What are the Key Features of Node.js ?
Node.js has gained immense popularity among developers for its ability to handle server-side operations efficiently and effectively. Built on Chrome’s V8 JavaScript engine, Node.js is designed to build scalable and high-performance applications. Here, we explore the key features that make Node.js a powerful tool for server-side development.
NodeJs = Runtime Environment + Javascript library
Table of Content
- Asynchronous and Event-Driven
- Working with Nodejs
- Key Features of Node.js
- Applications of Node.js
- Conclusion