Jadu 10–12 Week
--
In this blog, I am going to reflect on my 3 weeks of learning with Jadu.
We started our week by exploring Nodejs.
NodeJs?
Nodejs is a JavaScript runtime based on Chrome’s V8 JavaScript engine. It enables the creation of software. In JavaScript, that doesn’t depend on running in a web browser like Google Chrome, Firefox or Safari, etc. It’s extremely versatile, enabling the creation of tools for front-end and back-end applications. Nodejs can use as a cross-platform, we can use it equally on Linux, Windows, and macOS.
With Node.js, we can add server-side functionalities to our applications using JavaScript (JS).
History
Before the introduction of Node.js, JavaScript was recognized as a frontend programming language, which meant that it was only used to manage aspects of a web application visible to the user. Node.js is a game-changer. It allows developers to use JavaScript as a server-side language, effectively transforming JavaScript from frontend to full-stack.
It’s important to understand that Node.js isn’t a programming language, but a run time environment of a programming language. Node.js is labeled as a JavaScript run-time environment because it uses JavaScript to conduct backend processes.
Node.js is a pretty popular backend technology used by big companies likes Netflix and Uber.
// import the file system module
const fs = require('fs');
//create a new text filed called tasks and store the string "Book a book" to it
fs.writeFile('tasks.txt', 'Read a book', (error) =>{
if (error) throw error;
console.log('The file has been saved.')
});
- The file system module is passed to the variable called fs, which could be whatever name you think is appropriate
- The writeFile function takes three arguments: a filename, the data that is to be stored in the file, and a callback function.
- The callback function takes an error argument that’s only available if a problem arises when trying to execute the writeFile function.
Let's move to Express
Express
Express is a flexible Node.js web application framework that provides a robust set of features to develop web and applications.
- Allows to set up middlewares to respond to HTTP Requests.
- Defines a routing table that is used to perform different actions based on HTTP Method and URL.
- Allows to dynamically render HTML Pages based on passing arguments to templates.
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello from Express');
})
var server = app.listen(4000, function () {
var host = server.address().address
var port = server.address().port
console.log(host, port)
})
We are still learning ExpressJs. What we can do with Nodejs, exactly we can do with Express but faster and easier!
Khadija Batool Gardezi