Skip to content

Commit bb94b56

Browse files
authored
Update Node-and-Packages.md
1 parent e23cf8c commit bb94b56

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

Node-and-Packages.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,43 @@ To restart a running application
111111

112112
## 8. `express` Package
113113

114-
```javascipt
114+
`express` is a Node package that allows us to create web servers to host APIs that allow for http request, reponses and supports HTTP methods e.g GET and POST.
115+
116+
Install `express`
117+
118+
`npm install express`
119+
120+
An example of web server JavaScript code that will listen on a specific port and render "Hello, world" if the API address is visited.
121+
122+
#### index.js file
123+
124+
```javascript
125+
const express = require('express');
126+
const app = express();
127+
const port = 3000;
128+
129+
app.get('/', (request, response) => {
130+
response.send(`Hello World!`);
131+
});
132+
133+
app.listen(port, () => {
134+
console.log(`Example app listening at http://localhost:${port}`);
135+
});
115136
```
116137

138+
To run the `express` web server
139+
140+
```node index.js```
141+
142+
Edit the `package.json` to include a run script
143+
144+
```javascript
145+
"scripts": {
146+
"start": "node index.js"
147+
}
148+
```
149+
150+
Using the run script
151+
152+
```npm start```
117153

0 commit comments

Comments
 (0)