0

So I started to learning Node.js recently so far the gatherings all are good but I came across the concept of setup with jsconfig.json which largely helps to free the clutters made in mentioning the relative path and I decided to setup the same in my practicing node folder but unfortunately it doesn't work as expected , so this is my homecontroller.js file

"use strict"
const { request } = require('http');
const path=require('path');
const sbscrbrcntrllr=require('./subscribecontroller')

exports.getcntctfrm=(request,response)=>{
    response.sendFile(path.join(__dirname,'../views/contact.html'))
}

and this is my jsconfig.json file

{
    "compilerOptions": {
        "baseUrl": "./",
        "paths": {
            "@models/*":["models/"],
            "@controllers/*":["controllers/"],
            "@views/*":["views/"]
        }
    }
}

my folder will looks like this

-|
 |
 |- Controllers
 |    |-homecontroller.js
 |    |-subscribercontroller.js
 |- views
 |    |-contact.html
 |- index.js
 |- jscongig.json
 |- packages.json

my problem is that compiler is not reading properly and the error is something like this

Error: ENOENT: no such file or directory, stat '/home/scully86/organised-mongoose/controllers/@views/contact.html'

rather than particular with this I want a general work flow or syntax to work this out please suggest your tips

  • 1
    Note that that's not a Node thing, but something _specific_ to VS code. Node itself does not use `jsconfig.json` at all. It's purely there [to help VS Code](https://code.visualstudio.com/docs/languages/jsconfig) perform code resolution etc. better. It has zero effect on _running_ your project (and as such, it's actually a great idea to _not_ use one and stick with extensions that know how to help VS Code interpret code for whatever framework you've chosen to work with, like react, vite, etc. etc. ) – Mike 'Pomax' Kamermans Aug 27 '23 at 17:54
  • no I also suspects the VScode but I only showed the node code to get the clarity of implementation to my concept – Madhu mohan Aug 27 '23 at 18:10
  • You added paths to `compilerOptions`. What compiler do you use for your project? – jabaa Aug 27 '23 at 19:06
  • I suspect you have one too many dots in the string, `'../views/contact.html'`. – phatfingers Aug 28 '23 at 03:24

0 Answers0