4 NodeJS Scripting PDF
4 NodeJS Scripting PDF
●
First, create a folder inside your C:\ drive. Name
it “citcs”. See image below for reference
●
Inside the CITCS folder, I want you to create a
new file. Name it “server.js”.
– You may use notepad++ or VS Code to create a js
file. Just make it sure to save the file inside the citcs
folder.
– See next slide for reference
●
Open your command prompt
●
In your command prompt window, type the following:
– cd \
– cd citcs
– npm init
●
For package name, type “hello_world”
●
For version, skip it, just press enter
●
For description, enter “nodejs exercises”
●
For entry point, skip it, press enter.
●
For the succeeding entry, skip it.
●
For author, enter your name.
●
If being asked if everything is okay, just press enter.
●
Output
●
Let’s install the nodejs express framework.
– In the command prompt, type “npm install express -
s”
●
Open your entire “citcs” folder in VsCode Editor
●
Click the “server.js” file from the file explorer window inside the
VsCode Editor
●
Type the following inside the server.js file
●
In JavaScript ES6, semicolon is not required at
the end of your js code.
●
We defined the specific port number of our http
server using const port = 8000
●
To run our nodejs script, simply type node server.js in the command line