JavaScript Answers

How to fix “Cannot GET /” error with Connect on Node.js?

Spread the love

To fix "Cannot GET /" error with Connect on Node.js, we use the connect.static method.

For instance, we write

const connect = require("connect");

const app = connect().use(connect.static(__dirname + "/public"));

to call connect.static to expose the /public folder as a static files folder.

And then we call use to add the returned middleware to the app.

Then we can see the files in the folder when we go to /

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.