- Make new folder.
mkdir 01-express-101
- Open the folder.
cd 01-express-101
- Make sure you have
node
andnpm
installed in your computer.
node -v
npm -v
- Init
npm
for start the project.
npm init
- For now, just press
enter
if you asked to fill something. If done, filepackage.json
will appeared in your directory.
{
"name": "01-express-101",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
- Install the express
npm install express
- Create new file
index.js
touch index.js
- Copy this script.
const express = require("express");
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.get("/", (req, res) => {
res.send("Hello Express");
});
app.listen(3000, () => {
console.log("Running on localhost:3000");
});
- Try to run the script, and open
localhost:3000
.
node index.js
- Improve your script!