The command npm install express installs Express locally in your project folder, which is the standard way to add dependencies.
npm install -g express installs Express globally, which is not typical for libraries used in projects.
node install express is not a valid command.
npm add express is not a valid npm command.
http://localhost:3000/ in a browser?import express from 'express'; const app = express(); app.get('/', (req, res) => { res.send('Hello World!'); }); app.listen(3000);
The app listens on port 3000 and responds to GET requests at '/' with 'Hello World!'. Visiting http://localhost:3000/ will display that text.
const express = require('express') const app = express() app.get('/', (req, res) => { res.send('Hi') }) app.listen(3000
The app.listen(3000 line is missing a closing parenthesis, causing a SyntaxError.
The other options are incorrect because express is imported correctly with require, and res.send is valid.
express() do?The express() function creates an app object that you use to define routes and middleware, and to start the server.
Starting the server is done with app.listen().
port after execution?import express from 'express'; const app = express(); const port = process.env.PORT || 3000; app.listen(port);
The expression process.env.PORT || 3000 means if process.env.PORT is set (truthy), use it; otherwise, use 3000.
This allows the app to use a port from environment variables or default to 3000.