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

Time:02-20

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.

CodePudding user response:

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.

CodePudding user response:

try this

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