Advanced Node and Express - How to Use Passport Strategies: Error: ENOENT

Tell us what’s happening:
Describe your issue in detail here.

It throws an ENOENT error. I may need to change a path to include ‘index’, but I am not sure.

    throw err;

Error: ENOENT: no such file or directory, open '/home/runner/boilerplate-advancednode/index.js'

Your code so far

'use strict';
const express = require('express');
const myDB = require('./connection');
const fccTesting = require('./freeCodeCamp/fcctesting.js');
const session = require('express-session');
const passport = require('passport');
const ObjectID = require('mongodb').ObjectID;
const LocalStrategy = require('passport-local');
const mySecret = process.env['SESSION_SECRET']

const app = express();
app.set('view engine', 'pug');

fccTesting(app); // For fCC testing purposes
app.use('/public', express.static(process.cwd() + '/public'));
app.use(express.urlencoded({ extended: true }));

  secret: mySecret,
  resave: true,
  saveUninitialized: true,
  cookie: { secure: false }


myDB(async (client) => {
  const myDataBase = await client.db('database').collection('users');

  // Be sure to change the title
  app.route('/').get((req, res) => {
    // Change the response to render the Pug template
    res.render('/views/pug/index', {
      title: 'Connected to Database',
      message: 'Please login',
      showLogin: true

  // Serialization and deserialization here...
  passport.serializeUser((user, done) => {
    done(null, user._id);
  passport.deserializeUser((id, done) => {
    myDataBase.findOne({ _id: new ObjectID(id) }, (err, doc) => {
      done(null, doc);
  passport.use(new LocalStrategy(
    function(username, password, done) {
      myDataBase.findOne({ username: username }, function (err, user) {
        console.log('User '+ username +' attempted to log in.');
        if (err) { return done(err); }
        if (!user) { return done(null, false); }
        if (password !== user.password) { return done(null, false); }
        return done(null, user);
  // Be sure to add this...
}).catch((e) => {
  app.route('/').get((req, res) => {
    res.render('pug', { title: e, message: 'Unable to login' });
// app.listen out here...

app.listen(process.env.PORT || 3000, () => {
  console.log('Listening on port ' + process.env.PORT);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36

Challenge: How to Use Passport Strategies

Link to the challenge:

Hello there,

This is an issue with Replit. Common ways to avoid the issue are:

  • Opening the .replit file, before clicking the RUN button
  • renaming server.js to index.js - this might require you to remap some of the logic in the testing files - if you are unsure, ask.

Hope this helps

1 Like

I solved my issue with your first solution. Thank you :pray:t4: :pray:t4: :pray:t4:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.