How to create an Express project in Node.js
Creating an Express project provides a robust foundation for building web applications and APIs in Node.js with minimal configuration and maximum flexibility. As the creator of CoreUI, a widely used open-source UI library, I’ve set up countless Express projects for backend services and API development. From my 25 years of experience in web development and 11 years with Node.js, the most straightforward approach is to initialize a new npm project and install Express as a dependency. This method provides a clean starting point for scalable web applications.
Initialize a new npm project and install Express to create a basic web server foundation.
# Create project directory
mkdir my-express-app
cd my-express-app
# Initialize package.json
npm init -y
# Install Express
npm install express
# Create basic server file
touch app.js
// app.js
const express = require('express')
const app = express()
const port = 3000
app.use(express.json())
app.get('/', (req, res) => {
res.json({ message: 'Hello World!' })
})
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`)
})
The npm init -y command creates a package.json file with default settings. Installing Express adds the framework and its dependencies to your project. The basic server file imports Express, creates an application instance, configures JSON middleware, defines a simple route, and starts the server on port 3000. The express.json() middleware enables parsing of JSON request bodies for API functionality.
This is the same Express project setup we use in CoreUI backend services for creating scalable API endpoints and web applications.
For production projects, consider using the Express application generator with npx express-generator to create a more complete project structure with additional middleware and templating support.



