{"id":4676,"date":"2023-06-19T13:05:11","date_gmt":"2023-06-19T12:05:11","guid":{"rendered":"https:\/\/www.utilewebsites.nl\/knowledgebase\/an-introduction-to-node-js-building-server-side-applications-with-javascript\/"},"modified":"2023-06-19T13:15:26","modified_gmt":"2023-06-19T12:15:26","slug":"an-introduction-to-node-js-building-server-side-applications-with-javascript","status":"publish","type":"wz_knowledgebase","link":"https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/an-introduction-to-node-js-building-server-side-applications-with-javascript\/","title":{"rendered":"An Introduction to Node.js: Building Server-Side Applications with JavaScript"},"content":{"rendered":"\n<p>Below you will find an introduction on how to get started building server-side applications using JavaScript.<\/p>\n\n\n\n<p><strong>What is Node.js?<\/strong><\/p>\n\n\n\n<p>Node.js is a special execution environment for JavaScript that allows you to run JavaScript not only in your Web browser, but also on servers. It provides a platform for building powerful and scalable server-side applications. This allows you to use JavaScript to perform tasks such as processing requests, executing server logic and communicating with databases.<\/p>\n\n\n\n<p><strong>The difference between JavaScript on an HTML page and Node.js<\/strong><\/p>\n\n\n\n<p>The main difference between JavaScript on an HTML page and Node.js is the context in which they are executed. JavaScript on an HTML page is used to add interactive functionality to a Web page in a user's Web browser. It can be used to change the page based on events such as button clicks or form submissions.<\/p>\n\n\n\n<p>On the other hand, Node.js is used on servers to perform server-side tasks. It can handle network requests, read and write files, and access databases. With Node.js, you can build servers that can handle multiple requests simultaneously, making them ideally suited for developing scalable Web applications.<\/p>\n\n\n\n<p><strong>A simple Node.js example: An HTTP server<\/strong><\/p>\n\n\n\n<p>Now let's look at a simple example to get you started with Node.js. We are going to set up an HTTP server that responds to requests with a simple \"Hello World!\" message.<\/p>\n\n\n\n<p>Step 1: Create a new file called \"server.js\" and open it in a text editor. Step 2: Add the following code to the \"server.js\" file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Import the built-in HTTP module\nconst http = require('http');\n\n\/\/ Define the hostname and port number\nconst hostname = '127.0.0.1';\nconst port = 3000;\n\n\/\/ Create an HTTP server\nconst server = http.createServer((req, res) => {\n  \/\/ Set the status and headers\n  res.statusCode = 200;\n  res.setHeader('Content-Type', 'text\/plain');\n\n  \/\/ Send the \"Hello World!\" response\n  res.end('Hello World!\\n');\n});\n\n\/\/ Start the server and listen on the specified port number and hostname\nserver.listen(port, hostname, () => {\n  console.log(`Server started at http:\/\/${hostname}:${port}\/`);\n});\n\n<\/code><\/pre>\n\n\n\n<p>Step 3: Save the \"server.js\" file.<\/p>\n\n\n\n<p><strong>Running the Node.js server<\/strong><\/p>\n\n\n\n<p>Now we want to install Node.js on a Debian server and run our example:<\/p>\n\n\n\n<p>Step 4: Connect to you Debian server via SSH or open a terminal window on the server. Step 5: Run the following command to update your server's package lists:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\n<\/code><\/pre>\n\n\n\n<p>Step 6: Install Node.js using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install nodejs\n<\/code><\/pre>\n\n\n\n<p>Step 7: Verify that Node.js is installed correctly by checking the version:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>node -v\n<\/code><\/pre>\n\n\n\n<p>Step 8: In addition to Node.js, npm (Node Package Manager) is also installed. Check the version of npm with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm -v\n<\/code><\/pre>\n\n\n\n<p>Step 9: Go to the folder where you saved the \"server.js\" file and run the following command to start the Node.js server:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>node server.js\n<\/code><\/pre>\n\n\n\n<p>Step 10: The server is now active and listening at <a href=\"http:\/\/127.0.0.1:3000\/\">http:\/\/127.0.0.1:3000\/.<\/a> You can open your web browser and navigate to that URL to see the \"Hello World!\" message.<\/p>\n\n\n\n<p>Congratulations! You have just set up and tested your first Node.js server. This is just the beginning of what you can do with Node.js. You can use it to build more advanced server-side applications and take advantage of the power of JavaScript on the server.<\/p>\n\n\n\n<p>I hope this article has helped you better understand Node.js and provided a starting point to get started on your own. Good luck exploring and building great Node.js applications!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Below you will find an introduction on how to get started building server-side applications using JavaScript. What is Node.js? Node.js is a special execution environment for JavaScript that allows you to run JavaScript not only in your Web browser, but also on servers. It provides a platform for building powerful and scalable server-side applications. This allows you to use JavaScript to perform tasks such as processing requests, executing server logic and communicating with databases. The difference between JavaScript on an HTML page and Node.js The main difference between JavaScript on an HTML page and Node.js is the context in which&nbsp;<a href=\"https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/an-introduction-to-node-js-building-server-side-applications-with-javascript\/\" class=\"read-more\">Continue Reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"wzkb_category":[69],"wzkb_tag":[],"class_list":["post-4676","wz_knowledgebase","type-wz_knowledgebase","status-publish","hentry","wzkb_category-three-js-vue-js"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>An Introduction to Node.js: Building Server-Side Applications with JavaScript - Utilewebsites<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/an-introduction-to-node-js-building-server-side-applications-with-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"An Introduction to Node.js: Building Server-Side Applications with JavaScript - Utilewebsites\" \/>\n<meta property=\"og:description\" content=\"Below you will find an introduction on how to get started building server-side applications using JavaScript. What is Node.js? Node.js is a special execution environment for JavaScript that allows you to run JavaScript not only in your Web browser, but also on servers. It provides a platform for building powerful and scalable server-side applications. This allows you to use JavaScript to perform tasks such as processing requests, executing server logic and communicating with databases. The difference between JavaScript on an HTML page and Node.js The main difference between JavaScript on an HTML page and Node.js is the context in which&nbsp;Continue Reading\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/an-introduction-to-node-js-building-server-side-applications-with-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"Utilewebsites\" \/>\n<meta property=\"article:modified_time\" content=\"2023-06-19T12:15:26+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/knowledgebase\\\/an-introduction-to-node-js-building-server-side-applications-with-javascript\\\/\",\"url\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/knowledgebase\\\/an-introduction-to-node-js-building-server-side-applications-with-javascript\\\/\",\"name\":\"An Introduction to Node.js: Building Server-Side Applications with JavaScript - Utilewebsites\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/#website\"},\"datePublished\":\"2023-06-19T12:05:11+00:00\",\"dateModified\":\"2023-06-19T12:15:26+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/knowledgebase\\\/an-introduction-to-node-js-building-server-side-applications-with-javascript\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/knowledgebase\\\/an-introduction-to-node-js-building-server-side-applications-with-javascript\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/knowledgebase\\\/an-introduction-to-node-js-building-server-side-applications-with-javascript\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Knowledge Base\",\"item\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/knowledgebase\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"An Introduction to Node.js: Building Server-Side Applications with JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/\",\"name\":\"Utilewebsites\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/#organization\",\"name\":\"Utilewebsites\",\"url\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.utilewebsites.nl\\\/wp-content\\\/uploads\\\/2019\\\/08\\\/logo-Utilewebsites-2017.png\",\"contentUrl\":\"https:\\\/\\\/www.utilewebsites.nl\\\/wp-content\\\/uploads\\\/2019\\\/08\\\/logo-Utilewebsites-2017.png\",\"width\":3000,\"height\":593,\"caption\":\"Utilewebsites\"},\"image\":{\"@id\":\"https:\\\/\\\/www.utilewebsites.nl\\\/en\\\/#\\\/schema\\\/logo\\\/image\\\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"An Introduction to Node.js: Building Server-Side Applications with JavaScript - Utilewebsites","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/an-introduction-to-node-js-building-server-side-applications-with-javascript\/","og_locale":"en_US","og_type":"article","og_title":"An Introduction to Node.js: Building Server-Side Applications with JavaScript - Utilewebsites","og_description":"Below you will find an introduction on how to get started building server-side applications using JavaScript. What is Node.js? Node.js is a special execution environment for JavaScript that allows you to run JavaScript not only in your Web browser, but also on servers. It provides a platform for building powerful and scalable server-side applications. This allows you to use JavaScript to perform tasks such as processing requests, executing server logic and communicating with databases. The difference between JavaScript on an HTML page and Node.js The main difference between JavaScript on an HTML page and Node.js is the context in which&nbsp;Continue Reading","og_url":"https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/an-introduction-to-node-js-building-server-side-applications-with-javascript\/","og_site_name":"Utilewebsites","article_modified_time":"2023-06-19T12:15:26+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/an-introduction-to-node-js-building-server-side-applications-with-javascript\/","url":"https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/an-introduction-to-node-js-building-server-side-applications-with-javascript\/","name":"An Introduction to Node.js: Building Server-Side Applications with JavaScript - Utilewebsites","isPartOf":{"@id":"https:\/\/www.utilewebsites.nl\/en\/#website"},"datePublished":"2023-06-19T12:05:11+00:00","dateModified":"2023-06-19T12:15:26+00:00","breadcrumb":{"@id":"https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/an-introduction-to-node-js-building-server-side-applications-with-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/an-introduction-to-node-js-building-server-side-applications-with-javascript\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/an-introduction-to-node-js-building-server-side-applications-with-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.utilewebsites.nl\/en\/"},{"@type":"ListItem","position":2,"name":"Knowledge Base","item":"https:\/\/www.utilewebsites.nl\/en\/knowledgebase\/"},{"@type":"ListItem","position":3,"name":"An Introduction to Node.js: Building Server-Side Applications with JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/www.utilewebsites.nl\/en\/#website","url":"https:\/\/www.utilewebsites.nl\/en\/","name":"Utilewebsites","description":"","publisher":{"@id":"https:\/\/www.utilewebsites.nl\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.utilewebsites.nl\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.utilewebsites.nl\/en\/#organization","name":"Utilewebsites","url":"https:\/\/www.utilewebsites.nl\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.utilewebsites.nl\/en\/#\/schema\/logo\/image\/","url":"https:\/\/www.utilewebsites.nl\/wp-content\/uploads\/2019\/08\/logo-Utilewebsites-2017.png","contentUrl":"https:\/\/www.utilewebsites.nl\/wp-content\/uploads\/2019\/08\/logo-Utilewebsites-2017.png","width":3000,"height":593,"caption":"Utilewebsites"},"image":{"@id":"https:\/\/www.utilewebsites.nl\/en\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/www.utilewebsites.nl\/en\/wp-json\/wp\/v2\/wz_knowledgebase\/4676","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.utilewebsites.nl\/en\/wp-json\/wp\/v2\/wz_knowledgebase"}],"about":[{"href":"https:\/\/www.utilewebsites.nl\/en\/wp-json\/wp\/v2\/types\/wz_knowledgebase"}],"author":[{"embeddable":true,"href":"https:\/\/www.utilewebsites.nl\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.utilewebsites.nl\/en\/wp-json\/wp\/v2\/comments?post=4676"}],"version-history":[{"count":4,"href":"https:\/\/www.utilewebsites.nl\/en\/wp-json\/wp\/v2\/wz_knowledgebase\/4676\/revisions"}],"predecessor-version":[{"id":4681,"href":"https:\/\/www.utilewebsites.nl\/en\/wp-json\/wp\/v2\/wz_knowledgebase\/4676\/revisions\/4681"}],"wp:attachment":[{"href":"https:\/\/www.utilewebsites.nl\/en\/wp-json\/wp\/v2\/media?parent=4676"}],"wp:term":[{"taxonomy":"wzkb_category","embeddable":true,"href":"https:\/\/www.utilewebsites.nl\/en\/wp-json\/wp\/v2\/wzkb_category?post=4676"},{"taxonomy":"wzkb_tag","embeddable":true,"href":"https:\/\/www.utilewebsites.nl\/en\/wp-json\/wp\/v2\/wzkb_tag?post=4676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}