#### What Will I Learn? - How to create simple NodeJS server - How to make a static site - Running the server #### Requirements - No special requirements - NodeJS installed on your system - [Download Here](https://nodejs.org/en/) #### Difficulty - Basic #### Tutorial Contents This tutorial shows you how to run a NodeJS server and how to build it, it's easy and basic tutorial and this is gonna be a series of tutorials. ## Installing Node.js First of all, we need to install Node.js, go to the download link - https://nodejs.org/en/ and install the stable version  if you're not using windows go to this download link - https://nodejs.org/en/download/  and choose your own operating system. ## Creating the folder  press SHIFT + right click and open PowerShell window, then type > npm init then follow the screenshots (I'm using GIT Bash, it will be the same with PowerShell) press enter only if I didn't tell other.  (do not use names with spaces, if it is with space change it like I did)    change the index.js to server.js.     put your name or leave it blank  press enter here >  great! we done with the package.json. ## Creating basic server and run it go to your text editor, make a new js file in your folder. the file name needs to be the same as you put on the command line. if you didn't change the name to server.js(like I said to) the name will be "index.js".  Good, now we have a blank page, let's make a server! > const http = require('http'); first, we need to set a variable with the "HTTP"(which create the server). > const hostIP = "localhost"; //or "127.0.0.1" which is better for you. > const port = 80; //you can use any other port, like 3000 or something. now make 2 variables, the IP, and the port, you want to make variables so you can change it anytime you want to. now let's create a simple server, <blockquote> const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader('Content-type', 'text-plain'); res.end('Hello World! this is my first project at node.js!'); }); server.listen(port, hostIP, () => { console.log("Listen to port " + port); }); </blockquote> pastebin version(full script) -> https://pastebin.com/ex5AfL46 OR [Here](https://pastebin.com/ex5AfL46) when you done, save the script and creating a "server.bat"  and just put this command > node server if you followed all the steps it should work! let's start the "server.bat" if you're not using windows use the command line and type the same command, > node server then you should get this window  if you done it correctly go to your web browser and go to "localhost:80" if you're using port 80 you can just go "localhost", if you're using any other port use "localhost:PORT" and change "PORT" to your port.  as you can see, it's work perfectly! ## What we learn next time - Chat system based on socket.io <br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@lonelywolf/nodejs-tutorials-1-creating-a-static-site-node-js">Utopian.io - Rewarding Open Source Contributors</a></em><hr/>
author | lonelywolf | ||||||
---|---|---|---|---|---|---|---|
permlink | nodejs-tutorials-1-creating-a-static-site-node-js | ||||||
category | utopian-io | ||||||
json_metadata | {"community":"utopian","app":"utopian/1.0.0","format":"markdown","repository":{"id":27193779,"name":"node","full_name":"nodejs/node","html_url":"https://github.com/nodejs/node","fork":false,"owner":{"login":"nodejs"}},"pullRequests":[],"platform":"github","type":"tutorials","tags":["utopian-io","nodejs","node","tutorial","server"],"links":["https://nodejs.org/en/","https://nodejs.org/en/download/","https://pastebin.com/ex5AfL46","https://utopian.io/utopian-io/@lonelywolf/nodejs-tutorials-1-creating-a-static-site-node-js"],"image":["https://cdn.utopian.io/posts/3f0dea2c51f21e4d6a68dd8434e99ea13d04image.png","https://cdn.utopian.io/posts/bb27a2d20e770bac72d1a0cffcdb6fe22cc5image.png","https://cdn.utopian.io/posts/0ed4b235537ff89d5bdc1c59fc1a9ac8b67eimage.png","https://cdn.utopian.io/posts/9ff3ed949f81e52cf63a2da98d58919a439cimage.png","https://cdn.utopian.io/posts/b2c1966593d73849d638c9c83d158222c729image.png","https://cdn.utopian.io/posts/3982ceb2101b71d4f46ec3dfcb1b3e5201ebimage.png","https://cdn.utopian.io/posts/cacd6a799d4b15afe58aaea538885ea455ddimage.png","https://cdn.utopian.io/posts/475f7405fb8b1713f043d399f97231b55b58image.png","https://cdn.utopian.io/posts/a512aef7c395a70c2fafe83a9e0df08f0aabimage.png","https://cdn.utopian.io/posts/caa756d4d14ad6073b625007eae6ec870c2aimage.png","https://cdn.utopian.io/posts/504c7a167d5d529f7592b65034ab583f3196image.png","https://cdn.utopian.io/posts/a95a1f96970164a2b9b682584e91f56072b1image.png","https://cdn.utopian.io/posts/3e7a74321f86467582474ad051bd80c57116image.png","https://cdn.utopian.io/posts/9cbabbd5e225f69f77e3ace586978a3250b2image.png","https://cdn.utopian.io/posts/6feac5526338df81ca4f693992925191994dimage.png","https://cdn.utopian.io/posts/4cd270912cea2e45f746d3ac31c63f900a51image.png","https://cdn.utopian.io/posts/d1598582d1456bdae37103b2ca3b207389b6image.png"],"moderator":{"account":"zonguin","time":"2018-03-29T16:49:25.064Z","flagged":true,"reviewed":false,"pending":false},"questions":[],"score":null} | ||||||
created | 2018-03-27 18:33:24 | ||||||
last_update | 2018-03-29 16:49:24 | ||||||
depth | 0 | ||||||
children | 5 | ||||||
last_payout | 2018-04-03 18:33:24 | ||||||
cashout_time | 1969-12-31 23:59:59 | ||||||
total_payout_value | 0.310 HBD | ||||||
curator_payout_value | 0.075 HBD | ||||||
pending_payout_value | 0.000 HBD | ||||||
promoted | 0.000 HBD | ||||||
body_length | 4,589 | ||||||
author_reputation | 25,295,791,457,391 | ||||||
root_title | "NodeJS Tutorials #1 - Creating a static site [Node.JS]" | ||||||
beneficiaries |
| ||||||
max_accepted_payout | 1,000,000.000 HBD | ||||||
percent_hbd | 10,000 | ||||||
post_id | 46,948,441 | ||||||
net_rshares | 194,814,370,579 | ||||||
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
ubg | 0 | 204,938,046 | 1% | ||
guest123 | 0 | 852,648,962 | 100% | ||
danielfinn | 0 | 482,740,797 | 100% | ||
tuanis | 0 | 1,122,852,996 | 10% | ||
nomad-magus | 0 | 141,080,364,383 | 30% | ||
kingdavidharp | 0 | 5,347,037,726 | 100% | ||
lonelywolf | 0 | 6,278,936,574 | 100% | ||
chibikko-snap | 0 | 28,274,396,219 | 50% | ||
fel1xw | 0 | 1,535,756,203 | 70% | ||
kdanielmk | 0 | 523,988,573 | 100% | ||
glitterbot | 0 | 9,110,710,100 | 53.88% |
I tried following your tutorial but get this far and it no longer works for me in windows....  How do I proceed to the next step?
author | flxlove |
---|---|
permlink | re-lonelywolf-nodejs-tutorials-1-creating-a-static-site-node-js-20180612t133652080z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"image":["https://cdn.steemitimages.com/DQmewZ4wG188DtHdGibY4rur4bRdPaKLkgZPLJqVRcsKrRR/npm.png"],"app":"steemit/0.1"} |
created | 2018-06-12 13:36:48 |
last_update | 2018-06-12 13:36:48 |
depth | 1 |
children | 0 |
last_payout | 2018-06-19 13:36:48 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.034 HBD |
curator_payout_value | 0.004 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 228 |
author_reputation | 3,476,351,344,093 |
root_title | "NodeJS Tutorials #1 - Creating a static site [Node.JS]" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 60,447,006 |
net_rshares | 15,176,852,904 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
fumegi | 0 | 489,022,124 | 100% | ||
isnochys | 0 | 168,877,899 | 0.5% | ||
rdstm1985 | 0 | 521,605,794 | 100% | ||
cheaperwhale | 0 | 547,103,127 | 100% | ||
microbot | 0 | 4,112,126,699 | 21.4% | ||
minibot | 0 | 4,273,375,810 | 60% | ||
lovethiscomment | 0 | 1,198,018,625 | 100% | ||
millibot | 0 | 3,866,722,826 | 50% |
Your contribution cannot be approved because it does not follow the [Utopian Rules](https://utopian.io/rules). I cannot accept your contribution because they are basic instructions except for the part "creation of the server". But this last one lacks details and explanations *Submissions presenting content creation and simple on-screen instruction will be rejected.* You can contact us on [Discord](https://discord.gg/uTyJkNm). **[[utopian-moderator]](https://utopian.io/moderators)**
author | zonguin |
---|---|
permlink | re-lonelywolf-nodejs-tutorials-1-creating-a-static-site-node-js-20180329t165209054z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"} |
created | 2018-03-29 16:52:12 |
last_update | 2018-03-29 16:52:12 |
depth | 1 |
children | 3 |
last_payout | 2018-04-05 16:52:12 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 489 |
author_reputation | 12,831,796,837,639 |
root_title | "NodeJS Tutorials #1 - Creating a static site [Node.JS]" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 47,309,665 |
net_rshares | 0 |
Okay, thanks. hope next tutorial (chat system with socket.io) will be accepted.
author | lonelywolf |
---|---|
permlink | re-zonguin-re-lonelywolf-nodejs-tutorials-1-creating-a-static-site-node-js-20180329t165304718z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"app":"steemit/0.1"} |
created | 2018-03-29 16:53:24 |
last_update | 2018-03-29 16:53:24 |
depth | 2 |
children | 2 |
last_payout | 2018-04-05 16:53:24 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 79 |
author_reputation | 25,295,791,457,391 |
root_title | "NodeJS Tutorials #1 - Creating a static site [Node.JS]" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 47,309,835 |
net_rshares | 0 |
I hope too. Good continuation
author | zonguin |
---|---|
permlink | re-lonelywolf-re-zonguin-re-lonelywolf-nodejs-tutorials-1-creating-a-static-site-node-js-20180329t165358702z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"app":"steemit/0.1"} |
created | 2018-03-29 16:54:00 |
last_update | 2018-03-29 16:54:00 |
depth | 3 |
children | 1 |
last_payout | 2018-04-05 16:54:00 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 29 |
author_reputation | 12,831,796,837,639 |
root_title | "NodeJS Tutorials #1 - Creating a static site [Node.JS]" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 47,309,928 |
net_rshares | 0 |