Node.JS is a JavaScript runtime that is designed to build scalable network applications. It’s capable of utilizing JavaScript to run scripts server-side to produce dynamic web page content before the page is even sent to the browser of the user.
A Node.JS server is basically a server that’s powered by Node.JS. It’s built on Google Chrome’s V8 JavaScript engine. A lot of companies like Netflix, LinkedIn, and Uber use Node.JS in their tech stacks for its efficient and light performance making it ideal for microservices architectures.
Here’s a simple step-by-step guide on you can make a basic node.js server:
1. You need Node.js and NPM installed on your computer. You can download them from the official Node.js website.
1. Once you have it installed, you can now set up the Node.js server. You might want to create a new folder for your project and then open a terminal or command prompt in that directory.
1. In the command prompt, you can create a new file for your server code. Let’s call it server.js. You can create it by entering “touch server.js” in the terminal.
1. Open the server.js file in your choice of the text editor (like VS Code, Sublime Text, Notepad++, etc.). You can start writing your server script in there.
Here’s a basic one:
```
const http = require(‘http’);
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader(‘Content-Type’, ‘text/plain’);
res.end(‘Hello World\n’);
});
server.listen(3000, ’127.0.0.1’, () => {
console.log(‘Server running at http://127.0.0.1:3000/’)
});
```
This code tells your server to respond with ‘Hello World’ to any requests it receives.
1. You then run the server script from your terminal using the node command: `node server.js`.
1. Now, you can open your browser and visit `http://localhost:3000`. You should see ‘Hello World’ if successfully done.
Remember that Node.js is great for creating small, robust, fast systems, and can handle lots of connections concurrently.