node.js – Why do I have an error in require node js?
I’m trying to run some node.js code, however I get this error that module express doesn’t exist. And it seems that require keyword is the one that is raising the error: (File is a CommonJS module; it may be converted to an ES module)
I also had an error when trying to deploy the app in Render (with a start command of $node serverTest.js, build command $yarn and a runtime node).
I did install node.js
Why is this happening?
(I’m completely new to node.js and javascript)
const express = require('express');
const request = require('request');
const app = express();
const API_URL = 'openapi.naver.com'; // Replace this URL with your own
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
next();
});
app.get('/api', (req, res) => {
request(
{ url: `${API_URL}` },
(error, response, body) => {
if (error || response.statusCode !== 200) {
return res.status(500).json({ type: 'error', message: error.message });
}
res.json(JSON.parse(body));
}
);
});
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`listening on ${PORT}`));
//This is my comment
//This is my second comment
Read more here: Source link


