Managing Packages with Npm - getting error "Cannot find module 'express'" when using glitch

Managing Packages with Npm - getting error "Cannot find module 'express'" when using glitch


getting a log error from glitch regarding the express module which points to the server.js file:

Package.json file looks like this:

“author”: “Frederik Kars”,
“description”: “A project that does something awesome”,
“keywords”: [
“version”: “1.0”,
“license”: “MIT”,
“name”: “fcc-learn-npm-package-json”,
“dependencies”: {
“express”: “^4.16.3”,
“moment”: “^2.22.2”
“main”: “server.js”,
“scripts”: {
“start”: “node server.js”
“engines”: {
“node”: “8.11.2”
“repository”: {
“type”: “git”,
“url”: “https://idontknow/todo.git

cant figure out why i get the error. Have not change anything in the server.js file.

complete error code:
Error: Cannot find module ‘express’

at Function.Module._resolveFilename (module.js:547:15)

at Function.Module._load (module.js:474:25)

at Module.require (module.js:596:17)

at require (internal/module.js:11:18)

at Object. (/app/server.js:9:15)

at Module._compile (module.js:652:30)

at Object.Module._extensions..js (module.js:663:10)

at Module.load (module.js:565:32)

at tryModuleLoad (module.js:505:12)

at Function.Module._load (module.js:497:3)


Try installing it for the top of the package.json file


have tried - still getting the error


Can you share the url? Or the code for server.js?

Use 3 back ticks to format your code when posting here :slight_smile:


Hope its done right - here is the Server.js code:

 * the verification process may break
 * ***************************************************/

'use strict';

var fs = require('fs');
var express = require('express');
var app = express();

if (!process.env.DISABLE_XORIGIN) {
  app.use(function(req, res, next) {
    var allowedOrigins = ['', ''];
    var origin = req.headers.origin || '*';
    if(!process.env.XORIG_RESTRICT || allowedOrigins.indexOf(origin) > -1){
         res.setHeader('Access-Control-Allow-Origin', origin);
         res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");

app.use('/public', express.static(process.cwd() + '/public'));

  .get(function(req, res, next) {
    fs.readFile(__dirname + '/package.json', function(err, data) {
      if(err) return next(err);
    .get(function(req, res) {
		  res.sendFile(process.cwd() + '/views/index.html');

// Respond not found to all the wrong routes
app.use(function(req, res, next){
  res.type('txt').send('Not found');

// Error Middleware
app.use(function(err, req, res, next) {
  if(err) {
    res.status(err.status || 500)
      .send(err.message || 'SERVER ERROR');

app.listen(process.env.PORT, function () {
  console.log('Node.js listening ...');


It looks OK to me. Any chance to see the whole project?


sure thing - will this do or you need another view?!/alluring-velociraptor


I sent you a request to join the project so I can see the logs.


Fixed. Something weird on Glitch. I had to set a brand new content for the package.json so it refreshes from scratch and then paste your old code. Nothing wrong with your code but with Glitch itself.


Alright - Thanks for the help! :slight_smile: