Development Environment Setup
Registered members can download the FREE Get Started App. This is the project I used to compose articles about setting up VS Code and developing Node with Express and the Embedded JavaScript (EJS) view engine.
I developed quite a few ASP.NET Core websites with Visual Studio 20xx. For Express JS I found Visual Studio Code works better than the full IDE. This article describes how to set up node.js and express.js, with Visual Studio Code on Windows 11.
When I decided to learn Express, I found a lot of articles and AI suggestions which did not implement ES6 standards. ES6 or ECMAScript 2015 changed the landscape of JavaScript with the ability to create promises for asynchronous programming. I am familiar with ASP.NET Core and C# web applications and SQL Server databases. I developed this Express application with KenHaggerty.Com as a model. Registered members can download the FREE Get Started PostgreSQL app and Get Started MySQL app which implement this getting started with Express EJS tutorial.
Let's Talk About Express
Development Environment Setup
Features Since ECMAScript 2015(ES6)
Express EJS Template Engine
Express EJS Views, Layouts, and Partials
Express Error Handling
Express Routers and Controllers
Express Environment Variables
MySQL and Services
PostgreSQL and Services
EmailSender With Nodemailer
Express.js runs on the Node.js platform. To check if Node is installed and get the current version, open PowerShell or a command prompt and run:
node -v
If Node is not installed or the path environment variable is not set to where node is installed, typically "C:\Program Files\nodejs\", the result is:
If Node is not installed, download the Node Windows Installer. After installation, run the node -v command again.
Download and install Visual Studio Code from Install VS Code on Windows.
Create a project folder. Visual Studio 20xx implements a user > source > repos folder for the projects repository. I added a node folder to this repository. From your node projects repository, create a project folder like "get-started". From the project folder, right click and "Open in Terminal".
Launch the initialization utility with the "npm init" command. The npm CLI (Node Package Manager Command Line Interface) is installed with Node. This utility will walk you through creating a package.json file. Most of the defaults are fine for this tutorial except the entry point and type. Use server.js for the entry point and module for type. After initialization, install Express with the "npm install express" command.
You can launch VS Code for the project folder from the command line with "code .".
The first time you open the project folder with VS Code, you are asked to trust the authors.
From the Explorer tab, add a new file named server.js then add the server code to server.js.
server.js
import express from 'express'
const app = express();
const port = 3000;
app.get('/', (req, res) => {
res.send('Hello World!');
})
app.listen(port, () => {
console.log(`Get Started app listening on port ${port}`);
})
When you select the Run and Debug tab, you can create a launch.json file.
Select Node.js then escape the dropdown to create a simple Launch program configuration. I updated the name property to Debug and a default time zone property.
launch.json
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug",
"skipFiles": [
"<node_internals>/**",
"${workspaceFolder}/node_modules/**"
],
"program": "${workspaceFolder}\\server.js",
"env": {
"TZ": "UTC" // Set the time zone here
}
}
]
Save launch.json then start the Debug configuration. Notice the Debug Toolbar on the top right.
Open a browser and enter "http://localhost:3000".