First, you will need to create a project folder and then install the Express library.
To do this, open a terminal window and type:
npm install express --save
To do this, open a terminal window and type:
npm install express --save
Once installed, create a file called index.js in your project folder.
This is where you'll write the code for your server.
In the index.js file, add the following code to import the Express library and start the server:
This is where you'll write the code for your server.
In the index.js file, add the following code to import the Express library and start the server:
const express = require('express');
const app = express();
//create a route handler
app.get('/', (req, res) => {
res.send('Hello World!')
})
const port = 3000;
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
const app = express();
//create a route handler
app.get('/', (req, res) => {
res.send('Hello World!')
})
const port = 3000;
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
Finally, run your server by typing the following command in the terminal:
node index.js
Your server should now be running on port 3000.
node index.js
Your server should now be running on port 3000.
Open your browser and open this URL: http://localhost:3000
You should see: Hello World!
Congrats! You created your first Express app.
You should see: Hello World!
Congrats! You created your first Express app.
If you like this post, you can bookmark and tag it by replying with @SaveToBookmarks #nodejs #express
You can view your bookmarks on savetobookmarks.com
You can view your bookmarks on savetobookmarks.com
That's all, guys.
If you found this list useful, consider:
β Follow @csaba_kissi for more content like this
π Enable notifications π
π Retweeting the first tweet.
Thanks for your support, guys! ππ€
If you found this list useful, consider:
β Follow @csaba_kissi for more content like this
π Enable notifications π
π Retweeting the first tweet.
Thanks for your support, guys! ππ€
Loading suggestions...