19 Mar, 2024

Install NPM: 3 Advantages of NPM

To install npm, Node.js is required. Node.js has emerged as a popular platform for developing server-side applications and running JavaScript on the server. One of the key reasons behind its widespread adoption is the open-source libraries and tools available through the Node Package Manager (NPM). In this article, we will guide you through the process […]

Share your Love
3 mins read

Install angular

“Easily Install Angular and Unlock the Power of Web Development!” Angular is a powerful JavaScript framework used to create dynamic web applications. It is an open-source framework maintained by Google and a community of individual developers and corporations. Angular is a great choice for developing single-page applications as it provides a structured approach to building […]

Share your Love
12 mins read

Read file in Node.js

Asynchronously reads the entire contents of a file. var fs = require(‘fs’); var path = require(‘path’); exports.testDir = path.dirname(__filename); exports.fixturesDir = path.join(exports.testDir, ‘fixtures’); exports.libDir = path.join(exports.testDir, ‘../lib’); exports.tmpDir = path.join(exports.testDir, ‘tmp’); exports.PORT = +process.env.NODE_COMMON_PORT || 12346; // Read File fs.readFile(exports.tmpDir+’/world.csv’, ‘utf-8’, function(err, content) { if (err) { got_error = true; } else { console.log(‘cat returned […]

Share your Love
1 min read

Node.js Response.WriteHead function

Up until now all we’ve been sending into the writeHead function is the status code. However, it can take additional parameters like ‘Content-Length’, ‘Content-Type’. var http = require(‘http’); var fs = require(‘fs’); http.createServer(function(request, response) { response.writeHead(200, {‘Content-Type’: ‘text/html’} ); fs.readFile(‘index.html’, function(err, contents) { response.write(contents); response.end(); }); }).listen(8080);

Share your Love
1 min read

Node.js Read File from Server

Now, showing you how to create an HTTP non-blocking server and how to read a file of the non-blocking filesystem. var http = require(‘http’); var fs = require(‘fs’); http.createServer(function(request, response) { response.writeHead(200); fs.readFile(‘index.html’, function(err, contents) { response.write(contents); response.end(); }); }).listen(8080); Generate Request curl http://localhost:8080

Share your Love
1 min read