You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: index.md
+3-41Lines changed: 3 additions & 41 deletions
Original file line number
Diff line number
Diff line change
@@ -4,45 +4,13 @@
4
4
5
5
## Q. How to create a simple server in Node.js that returns Hello World?
6
6
7
-
**Step 01**: Create a project directory
8
-
9
-
```js
10
-
mkdir myapp
11
-
cd myapp
12
-
```
13
-
14
-
**Step 02**: Initialize project and link it to npm
15
-
16
-
```js
17
-
npm init
18
-
```
19
-
20
-
This creates a `package.json` file in your myapp folder. The file contains references for all npm packages you have downloaded to your project. The command will prompt you to enter a number of things.
21
-
You can enter your way through all of them EXCEPT this one:
22
-
23
-
```js
24
-
entry point: (index.js)
25
-
```
26
-
27
-
Rename this to:
28
-
29
-
```js
30
-
app.js
31
-
```
32
-
33
-
**Step 03**: Install Express in the myapp directory
34
-
35
-
```js
36
-
npm install express --save
37
-
```
38
-
39
-
**Step 04**: app.js
40
-
41
7
```js
42
8
/**
43
-
* Express.js
9
+
* Hello World using Express
44
10
*/
45
11
constexpress=require('express');
12
+
13
+
// create instance of express
46
14
constapp=express();
47
15
48
16
app.get('/', function (req, res) {
@@ -54,12 +22,6 @@ app.listen(3000, function () {
54
22
});
55
23
```
56
24
57
-
**Step 05**: Run the app
58
-
59
-
```bah
60
-
node app.js
61
-
```
62
-
63
25
**⚝[Try this example on CodeSandbox](https://codesandbox.io/s/hello-world-in-nodejs-ue3cs3)**
0 commit comments