,

Is Node.js simply JavaScript? Let’s explore.

Posted by

Node.js is a runtime environment that allows you to run JavaScript on the server side. While JavaScript is typically used for front-end development, Node.js allows you to use JavaScript for backend development as well. In this tutorial, we will explore what Node.js is and how you can start using it.

Before we dive into the details, it’s important to understand the difference between Node.js and regular JavaScript. While they both use the same language, Node.js provides a set of APIs that allow JavaScript to interact with the file system, network, and other server-side functionalities. This makes it possible to build web servers, command line applications, and other server-side applications using JavaScript.

To get started with Node.js, you first need to install it on your machine. You can download the installer from the official Node.js website and follow the instructions to install it on your system. Once Node.js is installed, you can start running JavaScript code on the server side.

To create a simple Node.js application, you can create a new file with a .js extension and open it in a code editor. Let’s create a simple "Hello World" application in Node.js:

<!DOCTYPE html>
<html>
<head>
  <title>Node.js Tutorial</title>
</head>
<body>
  <h1>Hello World!</h1>
</body>
</html>

In this example, we are creating a basic HTML file with a heading that says "Hello World." This is just a simple example to demonstrate how to run JavaScript on the server side using Node.js.

Now, let’s modify our HTML file to include some JavaScript code that will run on the server side using Node.js:

<!DOCTYPE html>
<html>
<head>
  <title>Node.js Tutorial</title>
</head>
<body>
  <h1 id="hello"></h1>

  <script>
    const http = require('http');

    const server = http.createServer((req, res) => {
      res.writeHead(200, { 'Content-Type': 'text/plain' });
      res.end('Hello World!');
    });

    server.listen(3000, 'localhost', () => {
      console.log('Server running at http://localhost:3000/');
    });
  </script>
</body>
</html>

In this example, we are using the http module in Node.js to create a simple web server that responds with "Hello World" when a request is made to the server. We are listening on port 3000 on localhost, so you can access the application by visiting http://localhost:3000 in your web browser.

This is just a basic example of what you can do with Node.js. Node.js provides a rich set of APIs and libraries that you can use to build powerful server-side applications. Whether you are building a web server, a real-time chat application, or a command-line tool, Node.js makes it easy to write JavaScript code on the server side.

In conclusion, Node.js is not just JavaScript – it is a powerful runtime environment that allows you to run JavaScript on the server side. By learning Node.js, you can expand your skill set and build a wide range of applications using JavaScript. I hope this tutorial has given you a better understanding of what Node.js is and how you can start using it in your projects. Happy coding!

0 0 votes
Article Rating
34 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@MisterBrausepulver
2 months ago

V8 is the runtime, Node just gibes you access to the API of the operating system.

@mio9525
2 months ago

i love how you guys finally decided to leave us alone and started yapping and fighting each other
js morons

@aresstavropoulos916
2 months ago

node is the runtime of javascript, if you only know javascript, you know 0% of node

@ludovicabomo9674
2 months ago

Thanks

@LunaticsOfLinkedIn
2 months ago

If you know how to breathe, you can code in js

@pawelmod3292
2 months ago

Haha, languages are mostly the same as runtimes? Laughing in Java(language with tons of running environment ) and .Net (different running environments for the same language and different languages first the same running env)

@imakhlaqXD
2 months ago

Ok he is over simplifying thigs. Frontend and backend is not something.
When you have multiple services and they are communicating via kafka or http, and you need to mange fault tolrence with circuitebreaker, u have auth server with openid connect to auth every requesr and a gateway for clinent to interact, a discover service to discover other services, loadbalancer to balance load between services, a cache layer, u have to do distubuted transction with 2phase commit or saga, to find something you have to do distributed logging, then Db getting more lead u have to switch to slave and master dbs, multiple dbs for read and one for write you have to maintain consistency between them, you have to streams data so you do not block main thread, you have to deploy your app first create docker image and run in k8 cluster.

YEP ITS SAME THING

@konga8165
2 months ago

lol, real languages are compiled

@psevdochlen6544
2 months ago

For who this?

@marcelosyd
2 months ago

Actually NodeJS is mostly c++ due v8

@alfredoperes651
2 months ago

melhor explicação, boa mano

@victorkochkarev2576
2 months ago

In a browser JavaScript working with DOM elemetnts, reacting to user interactions and making HTTP calls to fetch data.
On a server it is processing multiple requests made by a huge ammount of users, calling other services, quering databases, checking user permissions, listeninig to message queues, and logging what ever needs to be logged – but it is the same JavaScript – not a big difference.

@bigwalrus3901
2 months ago

What is a runtime

@onepunchman8721
2 months ago

Node.js = JavaScript + I/O operations

Bun.js = JavaScript + I/O operations

@jayleejw1801
2 months ago

sorry but javascript isn't a language. its a trash

@Daniel-yb5wc
2 months ago

I know JavaScript but for me to learned react was hard

@kirillzlobin7135
2 months ago

Best explanation!!! Finally someone said this

@seoun95
2 months ago

we call interpreter vs compiler

@cthutu
2 months ago

Node.js and the browser use the same runtime in the Chrome browser. This gentleman is wrong. What he refers to, incorrectly, as a runtime is the APIs available. Node.js and the browser provide access to different APIs. The runtime deals with garbage collection and other housekeeping tasks that are required at runtime.

@jonathanndawula8584
2 months ago

I ❤ JavaScript