I have a simple js file:
const bodyParser = require("body-parser");
const express = require("express");
const app = express();
// Set bodyparser
app.use(bodyParser.urlencoded({ extended : true }));
app.use(express.static('public'));
// Set ejs
app.set('view engine', 'ejs');
app.get("/", (req, res)=>{
console.log("an incoming request...");
res.render("index");
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, ()=>{
console.log("Listening...");
});
When I try to execute it with node server.js
, this appears:
SyntaxError: Invalid or unexpected token
at wrapSafe (internal/modules/cjs/loader.js:979:16)
at Module._compile (internal/modules/cjs/loader.js:1027:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
and with npm start
this happens:
> practice@1.0.0 start C:\Users\Youssef\Documents\Practice
> node server.js
C:\Users\Youssef\Documents\Practice\server.js:1
��c
SyntaxError: Invalid or unexpected token
at wrapSafe (internal/modules/cjs/loader.js:979:16)
at Module._compile (internal/modules/cjs/loader.js:1027:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! practice@1.0.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the practice@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\Youssef\AppData\Roaming\npm-cache\_logs\2020-12-31T21_42_52_634Z-debug.log
I don't understand why this happens, there isn't a syntax error in the code and i tested removing the get
route.
I cleaned npm cache, reinstalled node modules like in other stackoverflow questions: How to solve npm error "npm ERR! code ELIFECYCLE"
I even reinstalled nodejs and no good.
Thanks in advance.