'TypeError: exp.express is not a function. How to solve this problem when using express.js

I'm using Express.js for the first time. after using npm installed express. I'm writing following code in Atom:

import * as exp from "express";
app = exp.express();
app.listen(3000, function() {
  console.log("server start running");
});

because don't want to use require("express") for ES modules and have to use import...from.. after put node server.js it gives the following error at Hyper Terminal enter image description here

so how to fix this?

Thanks a lot.



Solution 1:[1]

Instead use import * as ...

You can simply do this:

import express from "express";

const app = express();

app.listen(3000, function() {
  console.log("server start running");
});

In this way you can import whole express module in a single import.

Solution 2:[2]

try this

import express from "express";
app = express();
app.listen(3000, function() {
  console.log("server start running");
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gianfabio Pezzolla
Solution 2