简体   繁体   中英

Error: listen EROFS: read-only file system /auth with Node and Express

I'm building a Mern application and I came across something unexpected that I don't know how to handle, I'm using Typescript on this as I'm learning it also. The problem is when I import the router and include the app listen '/auth' with the router path to the auth functions. And I get this error that is saying read-only file system /auth, but the problem is that /auth is not a directory rather it is an URL only, so that doesn't require any ready nor write access.

To not forget that I tried to chmod the folder, And I think that is not the case because it doesn't fix it.

And here is the error message:

Error: listen EROFS: read-only file system /auth
    at Server.setupListenHandle [as _listen2] (node:net:1302:21)
    at listenInCluster (node:net:1367:12)
    at Server.listen (node:net:1465:5)
    at Function.listen (/Users/bfzli/Code/bfzli-mern/server/node_modules/express/lib/application.js:618:24)
    at Object.<anonymous> (/Users/bfzli/Code/bfzli-mern/server/src/index.ts:11:5)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Module.m._compile (/Users/bfzli/Code/bfzli-mern/server/node_modules/ts-node/src/index.ts:1371:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/bfzli/Code/bfzli-mern/server/node_modules/ts-node/src/index.ts:1374:12)
    at Module.load (node:internal/modules/cjs/loader:981:32) {
  code: 'EROFS',
  errno: -30,
  syscall: 'listen',
  address: '/auth',
  port: -1
}
[nodemon] app crashed - waiting for file changes before starting...

Here is my Index:

import express, {Request, Response} from 'express'
const app = express()
require('dotenv').config({ path: __dirname+'/.env' });
const mongoose = require("mongoose");
const PORT: any = process.env.PORT;

mongoose.connect(process.env.MONGO_URL)
    .then((): void => console.log({succes: "Connected with Database."}))
.catch((error: any) => console.log({error: "Couldn't connected to Databse"}, {message: error}))

app.listen('/auth', require('./routes/Auth'))

app.listen(PORT, (): void => console.log(`Server started with port: ${PORT}`))

Here is my route and what it includes (in this case one function):

const router = require("express").Router()
const User = require('../models/User')

router.post('/register', async (req: any, res: any) => {
    try{
        const name = req.body.name;
        const username = req.body.name;
        const email = req.body.email;
        const password = req.body.password;
                
        const _THIS = new User({
            name, username, email, password
        })

        const _USER = await _THIS.save();

        res.status(200).send(_USER)

    }catch(error){
        res.status(500).send({message: "Something wrong happened."})
    }
})

module.exports = router

So the problem was that instead of using app.use(...), I used app.listen and this didn't the app run and give that weird error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM