Recebi esse erro no console ao mandar o npm start no terminal:
C:\Users\Deck Interiores\Desktop\Cursos\JS BROWSER E PADRÕES DE PROJETO\aluraframe\server> npm start
> app@1.0.0 start C:\Users\Deck Interiores\Desktop\Cursos\JS BROWSER E PADRÕES DE PROJETO\aluraframe\server
> node server.js
file:///C:/Users/Deck%20Interiores/Desktop/Cursos/JS%20BROWSER%20E%20PADR%C3%95ES%20DE%20PROJETO/aluraframe/server/server.js:1
var http = require('http')
^
ReferenceError: require is not defined
at file:///C:/Users/Deck%20Interiores/Desktop/Cursos/JS%20BROWSER%20E%20PADR%C3%95ES%20DE%20PROJETO/aluraframe/server/server.js:1:12
←[90m at ModuleJob.run (internal/modules/esm/module_job.js:110:37)←[39m
←[90m at async Loader.import (internal/modules/esm/loader.js:179:24)←[39m
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! app@1.0.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the app@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Deck Interiores\AppData\Roaming\npm-cache\_logs\2022-01-31T21_35_30_421Z-debug.log
PS C:\Users\Deck Interiores\Desktop\Cursos\JS BROWSER E PADRÕES DE PROJETO\aluraframe\server>
Código com a referência:
var http = require('http')
,app = require('./config/express');
http.createServer(app).listen(3000, function() {
console.log('Servidor estutando na porta: ' + this.address().port);
});
Dados do package.json:
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.15.1",
"express": "^4.12.3"
},
"type": "module"
}
Como resolver?