[Node.js] Set the Node.js Project to ECMAScript Modules (ESM)
Node.js projects have two ways that you can import and export code into different files. This is through CommonJS (CJS) and ECMAScript modules (ESM).
CommonJS is Node's default way to import modules but because I like to have my Node.js code similar to my frontend code, we will use ESM for this project.
To do so we will set a project type
in our package.json
.
"type":"module",
So, CommonJS module:
const http = require('http');
module.exports = {
name: 'JS'
}
ESM Module:
import http from "http";
export const name = "JS"
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2021-08-05 [Unit Testing + Jest + Node server] Testing a Node middleware with Jest
2021-08-05 [Unit testing + Jest] Use jest-in-case to Reduce Duplication and Improve Test Titles
2021-08-05 [Unit testing] Improve Error Messages by Generating Test Titles
2021-08-05 [Typescript] Extends and override an existing interface
2021-08-05 [SAA + SAP] 20. Other services - 1 (StackSets, EMR, SWF, Opsworks, WorkSpaces)
2016-08-05 [AngularJS] Accessible Button Events
2016-08-05 [React Native] Complete the Notes view