I've been using Glitch to host my node.js scripts and when I try and setup node.js, I get an error. I expected to setup express the same way I would with Replit but I'm keep getting the same error. It works fine if I go in the terminal and enter node server.js
The error
Error: Cannot find module 'express'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
My server.js
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
// using example code from expressjs.com
My package.json
{
"scripts": {
"start": "node server.js"
},
"dependencies": {
"node.js": "^10.24.1",
"express": "^4.19.2"
}
}
I think something is wrong with my package.json but I have no idea what it is. Also, this is a completely new project meaning there are only these two files and glitches built-in npm libraries.
Did you use npm i express
?
if it doesn't work delete package.json file and use npm init
. then npm i express
.